Answer lookup: Add 'no peeking' mode; don't show answers at or beyond today's Wordle. (Trivial to work around, but allows for narrow searches.)

This commit is contained in:
John 2022-02-12 06:22:45 -06:00
parent 5452552875
commit aa26089386

View File

@ -7,19 +7,32 @@ from datetime import date
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='A barebones CLI Wordle clone, using official Wardle solutions. Also a Wordle cheating tool. You have been warned.' description='A barebones CLI Wordle clone, using official Wardle solutions. Also a Wordle cheating tool. You have been warned.'
) )
parser.add_argument('day', type=int, nargs="?", help="Wordle day number") parser.add_argument('day', nargs="?", type=int, help="Wordle day number")
parser.add_argument('-l', metavar="solution", help="look up the day of a given solution") parser.add_argument('-l', metavar="solution", help="look up the day of a given solution")
parser.add_argument('-d', metavar="day", type=int, help="look up the solution of a given day") parser.add_argument('-d', metavar="day", type=int, help="look up the solution of a given day")
parser.add_argument('-g', metavar="guesses", type=int, help="number of guesses") parser.add_argument('-g', metavar="guesses", type=int, help="number of guesses")
parser.add_argument('--hard', action='store_true', help="enable hard mode")
# Parse the args # Parse the args
args = parser.parse_args() args = parser.parse_args()
# Handle the args # Handle the args
# Get today's day number
if args.day is not None:
# Ahoy-hoy, time traveller!
d = args.day
else:
# find num. days since Wordle launch
d = (date.today() - date(2021, 6, 19)).days
# l is for "Find this word in the answers list" # l is for "Find this word in the answers list"
if args.l: if args.l:
l = args.l.lower()
# Look up the answer's index # Look up the answer's index
print (w.Answers.index(args.l)) if l in w.Answers and w.Answers.index(l) < d:
print ("Wordle {}: {}".format(w.Answers.index(l), l))
else:
print ("{} is not a Wordle (yet)".format(args.l))
exit(0) exit(0)
# d is for "Find this day's answer" # d is for "Find this day's answer"
@ -31,8 +44,13 @@ if args.d != None:
print ("No Solution") print ("No Solution")
exit(0) exit(0)
if args.g:
max_guesses = args.g
else:
max_guesses = 6
# Get today's day number # Get today's day number
if args.day: if args.day is not None:
# Ahoy-hoy, time traveller! # Ahoy-hoy, time traveller!
d = args.day d = args.day
else: else:
@ -48,11 +66,16 @@ a = ["⬛", "🟨", "🟩"]
# Guesses go here # Guesses go here
g = [] g = []
# Hits/Misses go here
h = ""
m = ""
# C R A N E # C R A N E
hints = [0, 0, 0, 0, 0] hints = [0, 0, 0, 0, 0]
def wordbox(word): def wordbox(word):
b = "" b = ""
global h, m
wordlist = list(wotd) wordlist = list(wotd)
for i in range(len(word)): for i in range(len(word)):
if word[i] == wotd[i]: if word[i] == wotd[i]:
@ -62,7 +85,8 @@ def wordbox(word):
wordlist[i] = 0 wordlist[i] = 0
# add "🟩" to line # add "🟩" to line
b += a[2] b += a[2]
# Mark the hit
h += word[i]
elif word[i] in wordlist: elif word[i] in wordlist:
# Mark as hinted (wrong place) # Mark as hinted (wrong place)
hints[wordlist.index(word[i])]= 1 hints[wordlist.index(word[i])]= 1
@ -70,16 +94,19 @@ def wordbox(word):
wordlist[wordlist.index(word[i])] = 0 wordlist[wordlist.index(word[i])] = 0
# Add "🟨" to line # Add "🟨" to line
b += a[1] b += a[1]
# Mark the hit
h += word[i]
else: else:
# Add "⬛" to line # Add "⬛" to line
b += a[0] b += a[0]
m +=word[i]
print(b) print(b)
def game(): def game():
print ("[ Wordle {} ]".format(d)) print("[ Wordle {}{} ]".format(d, "*" if args.hard else " "))
words = w.Words + w.Answers words = w.Words + w.Answers
guess = 0 guess = 0
while guess < 6: while guess < max_guesses:
ui = input() ui = input()
if len(ui) == 5 and ui in words: if len(ui) == 5 and ui in words:
g.append(ui) g.append(ui)
@ -90,14 +117,13 @@ def game():
else: else:
guess += 1 guess += 1
else: else:
if ui == "exit":
exit()
print ("Not in word list") print ("Not in word list")
win(False) win(False)
def win(won): def win(won):
if won: print("\nWordle {} {}/{}{}\n".format(d, len(g) if won else "X", max_guesses, "*" if args.hard else ""))
print("\nWordle {} {}/6\n".format(d, len(g)))
else:
print("\nWordle {} X/6\n".format(d))
for gi in g: for gi in g:
wordbox(gi) wordbox(gi)