in src/engine/kanagramgame.cpp: void KanagramGame::createAnagram() { QString anagram; QString letters; int randomIndex; do { letters = m_originalWord; while (!letters.isEmpty()) { randomIndex = m_random.getLong(letters.count()); anagram.append(letters.at(randomIndex)); letters.remove(randomIndex, 1); } } while (anagram == m_originalWord); m_anagram = anagram; } the do while loop does not reset the QString anagram if anagram == m_originalWord, but instead appends the anagram to the duplicated original word. As a result, sometimes a bad anagram shows up. Most of the time this happens for particularly short words like "mir". Reproducible: Sometimes
Created attachment 86439 [details] proposal for a fix Simple idea for fixing: just insert anagram.clear() at the beginning of the do while loop. This is no particularly pretty solution as it performs a second initialization of the string.
Created attachment 86440 [details] fix the problem and avoid infinite loop While it does not make much sense in an anagram game to have a word that is only of a series of the same character, I still think this should be handled well. Without the previous patch this will *always* trigger the bug this report is about, i. e. if the word is e.g. the Finnish town Ii, the displayed anagram is iiii. After applying the previous patch, no anagram will be shown in that case and instead the program runs into an infinite loop, not responding anymore. This revised patch takes that case into account.
This does look like a better fix indeed. Do you have an account to commit this fix? If not I'll commit it for you, just let me know. thanks, Jeremy
(In reply to comment #3) > This does look like a better fix indeed. Do you have an account to commit > this fix? If not I'll commit it for you, just let me know. I do not have an account. Thank you for committing.
Git commit 94d899c449a91e8e3863c94316401b74a13bdae2 by Jeremy Whiting. Committed on 04/05/2014 at 03:02. Pushed by whiting into branch 'master'. Fix anagram creation duplicating letters when word is short. Thanks to <walch.martin@web.de> for the patch. FIXED-IN: 4.13.1 M +20 -15 src/engine/kanagramgame.cpp http://commits.kde.org/kanagram/94d899c449a91e8e3863c94316401b74a13bdae2
Git commit bf0bffd42c971e0a96a9e2297c2573a9db18546a by Jeremy Whiting. Committed on 04/05/2014 at 03:02. Pushed by whiting into branch 'KDE/4.13'. Fix anagram creation duplicating letters when word is short. Thanks to <walch.martin@web.de> for the patch. FIXED-IN: 4.13.1 (cherry picked from commit 94d899c449a91e8e3863c94316401b74a13bdae2) M +20 -15 src/engine/kanagramgame.cpp http://commits.kde.org/kanagram/bf0bffd42c971e0a96a9e2297c2573a9db18546a