samedi 12 février 2022

Complex random selection conditions

I'm still somewhat of a beginner in python, and my latest project has been a wordle bot, using only basic libraries (random, time). In one specific part of the project, I need to generate a new word based on knowledge known from another word. This is the code I am using right now. Some of the names may be confusing, so feel free to ask me.


while cmet == False:
    n_guess = []
    count = 0 
    for i in ne_guess:
      n_guess.append(i)
    ne_guess = random.choice(words)
    for i in comp_guess:
      if comp_guess[count] == 'green':
        if n_guess[count] == 'green':
          criteria = True
      elif comp_guess[count] == 'yellow':

        if n_guess[count] != 'yellow' and comp_guess[count] in n_guess:
          criteria2 = True
      elif comp_guess[count] == 'gray':
        if n_guess[count] not in comp_guess[count]:
          criteria3 = True
      if criteria == True and criteria2 == True and criteria3 == True:
        cmet = True
        count+=1
        print(n_guess)
        print(c_word)
        time.sleep(2)
      else:
        ne_guess = random.choice(words)

essentially, if a letter is "green" that means it is in that word, and in that spot. if a letter is yellow, it is in the word, but not in the spot. If the letter is gray, that means the word does not contain that letter. Basic wordle stuff. When I run, no matter what I try to change, the code continuously evaluates the same word, instead of changing the word which is evaluated. what i've tried: printing different components to check where im going wrong. output:A new word is generated, but the same word is evaluated. changing the code a billion times. output: error persists no matter the formatting. I would appreciate some help. I am happy to comment full code if anyone needs it.




Aucun commentaire:

Enregistrer un commentaire