#Wordle game AI, help

33 messages · Page 1 of 1 (latest)

quiet zincBOT
#

This post has been reserved for your question.

Hey @sleek shuttle! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

sleek shuttle
#
public void eliminateWords(WordleWord feedback) {
        prevWords.add(feedback.getWordString());
        List<Character> mustContain = new ArrayList<>();
        List<String> newPossibleWords = new ArrayList<>();

        int counter = 0;
        for(WordleCharacter wordleChar : feedback){
                if (wordleChar.answerType == AnswerType.WRONG){
                    this.wrongCharList.add(wordleChar.getLetter());
                }
                if (wordleChar.answerType == AnswerType.CORRECT){
                    correctHashMap.computeIfAbsent(wordleChar.getLetter(), a -> new ArrayList<>()).add(counter);
                    if(mustContain.indexOf(wordleChar.getLetter()) == -1){
                        mustContain.add(wordleChar.getLetter());
                    }
                }
                if (wordleChar.answerType == AnswerType.WRONG_POSITION){
                    wronglyplacedHashMap.computeIfAbsent(wordleChar.getLetter(), b -> new ArrayList<>()).add(counter);
                    if(mustContain.indexOf(wordleChar.getLetter()) == -1){
                        mustContain.add(wordleChar.getLetter());
                    }
                }
                counter++;
        }
        outerloop: for (String word : getAllWords()){

            //Check if the word is guessed on before
            if(this.prevWords.indexOf(word) != -1){
                continue outerloop;
            }

            //blabla
            Integer index = -1;
            for(Character c : word.toCharArray()){
                index++;

                //check if any chars of the new word has been guessed before
                if(this.wrongCharList.indexOf(c) != -1){
                    continue outerloop;
                }

                //check if the new word has wronglyplaced char where it has been before
                ```
#
                if(wronglyplacedHashMap.containsKey(c)){
                    ArrayList<Integer> values1 = wronglyplacedHashMap.get(c);
                    if(values1.contains(index)){
                        continue outerloop;
                    }
                }

                //check if the new word has all the correct chars at index
                if(correctHashMap.containsKey(c)){
                    ArrayList<Integer> values2 = correctHashMap.get(c);
                    if(!values2.contains(index)){
                        continue outerloop;
                    }
                }
            }

            Integer count = 0;
            for(int i = 0; i<5; i++){
                Character currentChar = word.charAt(i);
                if(mustContain.indexOf(currentChar) != -1){
                    count++;
                }
                if(correctHashMap.containsKey(currentChar)){
                    if(!correctHashMap.get(currentChar).contains(i)){
                        continue outerloop;
                    }
                }
            }
            if(count>=mustContain.size()){
                newPossibleWords.add(word);
            }
        }
        this.possibleAnswers = newPossibleWords;
    }
#

Usually it runs like this^

#

It takes in a long list of all the words. My functions goal is to for each iteration check the last guess and keep a note of which letters that give me a grey answer (answer word does not include) and also keep track of which letters are correct. Yellow is correct letter but wrongly placed (i want to keep those and guess them another spot in order to find the correct spot) and I want to keep the greens like they are. And always place them there they where correct

#

Some rare times my code just goes crazy and:

#

Like wtf.... That is not even possible with the way my code works?????? I continue outerloop;on every case where the word has 1 char correctly placed but it is not on that spot... continue outerloop should just skip the word because it cant be the word because the green letter is not there..

#
//check if the new word has all the correct chars at index
                if(correctHashMap.containsKey(c)){
                    ArrayList<Integer> values2 = correctHashMap.get(c);
                    if(!values2.contains(index)){
                        continue outerloop;
                    }
                }

This code should eliminate all the words where the greens are not in the correct spot

#

How come my R not be on the next guess??

#

another game:

#

Here the greens do what I want them too....

wicked oriole
#

keeping all correct letters may not be a great way to go about that

#

have you seen 3b1b's video about wordle and information theory?

sleek shuttle
#

in this task i am supposed to do it

#

in a later task i will optimize the ai with guessing the most common letters etc

sleek shuttle
#

@wicked oriolesorry to tag you but why does not my code always put the green in the new word?

#

n at the bottom right

#

help

#

!help

wicked oriole
sleek shuttle
#

yes

#

rewritten it 1000x times

wicked oriole
#

no, have you stepped through it

sleek shuttle
#

Yes

#

like how could the n not continue beneath there