我正在制作一个 Wordle AI 机器人,需要一些帮助。我的机器人并不喜欢删除单词,它不能基于上一轮的反馈,然后从下一轮的可能单词中随机选择一个单词。我需要帮助处理“灰色”字母。令人讨厌的是,由于单词带有双字母,所以我不能删除所有带有灰色字母的单词。例如,答案肯定是 LUNCH,而第二个字母 L 基本上是 HELLO。
注意 letter_states 对于字母为-1,对于灰色为 0,对于绿色为 1。注意 guess_counter 是从 0 到 6 的转弯。注意 letter 是字母表中每个字母的列表。注意 letter_index 对应于字母在字母表中的位置。因此 0 对应于 A,5 对应于 F。
if guess_counter == 0:
self.dictionary_copy = list(self.dictionary)
return (random.choice(self.dictionary_copy))
# If not first guess
else:
for letter_index in range(len(letter_states)):
if letter_states[letter_index] == 1: # 1 means green
words_to_remove = []
for word in self.dictionary_copy:
if self.letters[letter_indexes[letter_index]] not in word[letter_index]:
words_to_remove.append(word)
for word in words_to_remove:
self.dictionary_copy.remove(word)
elif letter_states[letter_index] == -1: # -1 means yellow
words_to_remove = []
for word in self.dictionary_copy:
if self.letters[letter_indexes[letter_index]] not in word or self.letters[letter_indexes[letter_index]] in word[letter_index]:
words_to_remove.append(word)
for word in words_to_remove:
self.dictionary_copy.remove(word)
elif letter_states[letter_index] == 0: # 0 means grey
words_to_remove = []
for word in self.dictionary_copy:
if self.letters[letter_indexes[letter_index]] in word[letter_index]:
words_to_remove.append(word)
for word in words_to_remove:
self.dictionary_copy.remove(word)
return (random.choice(self.dictionary_copy))
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(49条)