g: Potentially fix letter colorification in the case of duplicated letters
This commit is contained in:
parent
923569a944
commit
a499cbcc78
60
src/g.py
60
src/g.py
@ -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]:
|
||||||
line[i] = 2
|
# Mark the letter 'green' (2)
|
||||||
# Mark as hinted (right place)
|
line[i] = 2
|
||||||
hints[i] = 2
|
# Remove letter from solution and guess
|
||||||
wordlist[i] = 0
|
sol[i] = guess[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()
|
Loading…
Reference in New Issue
Block a user