1

ハングマン ゲームの AI を作成しようとしています。その一部では、単語リスト内の可能な各文字の出現回数をすべてカウントする必要があります。このカウントの前に単語リストをカリングして、物事をより速く実行することを計画しています (最初に推測可能なフレーズと同じ長さではないすべての単語を選別し、次に推測された文字と一致しない単語を選別します)。

私が抱えている問題は、以下のコードにあります。どういうわけか、正しい長さ (可能な文字数と一致する) の e のリストを常に返します。ここで何が間違っているのか正確にはわかりませんが、問題は間違いなく countCharacters のどこかにあります。

MethodicComputer(){
    guessable = parseGuessable();
    wordList = parseText();
    priorities = countCharacters(guessable);
}


public char guessCharacter(String hint){
    char guess = 0;
    System.out.println(guessable);
    System.out.println(priorities);
    guess = priorities.charAt(0);
    priorities = priorities.replaceAll("" + guess, "");

    return guess;
}

private String countCharacters(String possibleChars){
    charCount = new Hashtable();
    String orderedPriorities = "";
    char temp = 0;
    char adding = 0;
    int count = 0;
    int max = 0;
    int length = possibleChars.length();

    for (int i = 0; i<length; i++){
        temp = possibleChars.charAt(i);
        count = wordList.length() - wordList.replaceAll("" + temp, "").length();
        charCount.put(temp, count);
    }

    while (orderedPriorities.length() < length){
        for (int i = 0; i < possibleChars.length(); i++){
            temp = possibleChars.charAt(i);
            if (max < (int) charCount.get(temp)){
                max = (int) charCount.get(temp);
                adding = temp;
            }
        }
        orderedPriorities += adding;
        possibleChars = possibleChars.replaceAll("" + adding, "");
    }

    return orderedPriorities;
}
4

1 に答える 1