g: Potentially fix letter colorification in the case of duplicated letters

This commit is contained in:
John 2022-02-14 01:56:37 -06:00
parent 923569a944
commit a499cbcc78

View File

@ -55,50 +55,49 @@ else:
# Get today's word # Get today's word
if args.word: if args.word:
wotd = args.word solution = args.word
# Indicate a non-standard word # Indicate a non-standard word
d = args.word d = args.word
# If solution not in words list, enable nonsense
if solution not in w.Words + w.Answers:
args.nonsense = True
else: else:
if d >= len(w.Answers): if d >= len(w.Answers):
d = len(w.Answers) - 1 d = len(w.Answers) - 1
wotd = w.Answers[d] solution = w.Answers[d]
# End arg parsing
# ! The game is below this point
# Box characters! # Box characters!
a = ["", "🟨", "🟩"] boxes = ["", "🟨", "🟩"]
# Guesses go here # Guesses go here
g = [] guesses = []
# C R A N E
hints = [0, 0, 0, 0, 0]
def wordbox(word): def wordbox(word):
b = "" output = ""
global hints
wordlist = list(word)
line = [0] * len(word) line = [0] * len(word)
guess = list(word)
sol = list(solution)
# Green pass # Green pass
for i in range(len(word)): for i in range(len(word)):
if word[i] == wotd[i]: if guess[i] == sol[i]:
# Mark the letter 'green' (2)
line[i] = 2 line[i] = 2
# Mark as hinted (right place) # Remove letter from solution and guess
hints[i] = 2 sol[i] = guess[i] = 0
wordlist[i] = 0
# Yellow pass # Yellow pass
for i in range(len(word)): for i in range(len(word)):
if wordlist[i] and word[i] in wotd: if guess[i] and word[i] in sol:
# Mark the letter 'yellow' (1)
line[i] = 1 line[i] = 1
# Mark as hinted (wrong place) # Remove letter from solution and guess
hints[wordlist.index(word[i])]= 1 sol[sol.index(word[i])] = guess[i] = 0
# Remove letter from wordlist # Turn blocks into a string, and print it
wordlist[i] = 0
# Blockify pass
for i in line: for i in line:
b += a[i] output += boxes[i]
print(b) print(output)
def game(): def game():
print("[ Wordle {}{} ]".format(d, "*" if args.hard else " ")) print("[ Wordle {}{} ]".format(d, "*" if args.hard else " "))
@ -107,9 +106,9 @@ def game():
while guess < max_guesses: while guess < max_guesses:
ui = input().lower() ui = input().lower()
if len(ui) == 5 and (ui in words or args.nonsense): if len(ui) == 5 and (ui in words or args.nonsense):
g.append(ui) guesses.append(ui)
wordbox(ui) wordbox(ui)
if (ui == wotd): if (ui == solution):
win(True) win(True)
return return
else: else:
@ -121,8 +120,9 @@ def game():
win(False) win(False)
def win(won): def win(won):
print("\nWordle {} {}/{}{}\n".format(d, len(g) if won else "X", max_guesses, "*" if args.hard else "")) print("\nWordle {} {}/{}{}\n".format(d, len(guesses) if won else "X", max_guesses, "*" if args.hard else ""))
for gi in g: for gi in guesses:
wordbox(gi) wordbox(gi)
print() print()
game() game()