2022-02-12 16:45:33 +00:00
|
|
|
#!/usr/bin/python3
|
2022-02-12 11:33:23 +00:00
|
|
|
import w
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
# Set up argument parser
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='A barebones CLI Wordle clone, using official Wardle solutions. Also a Wordle cheating tool. You have been warned.'
|
|
|
|
)
|
2022-02-12 12:22:45 +00:00
|
|
|
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('-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")
|
2022-02-12 16:11:32 +00:00
|
|
|
parser.add_argument('--word', metavar="wotd", help="force a particular word")
|
|
|
|
parser.add_argument('--nonsense', action='store_true', help="allow nonsensical guesses")
|
|
|
|
parser.add_argument('--hard', action='store_true', help="enable hard mode (wip)")
|
2022-02-12 12:26:48 +00:00
|
|
|
# TODO: Implement hard mode properly (more than just a *)
|
2022-02-12 11:33:23 +00:00
|
|
|
|
|
|
|
# Parse the args
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Handle the args
|
2022-02-12 12:22:45 +00:00
|
|
|
# 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
|
|
|
|
|
2022-02-12 11:33:23 +00:00
|
|
|
# l is for "Find this word in the answers list"
|
|
|
|
if args.l:
|
2022-02-12 12:22:45 +00:00
|
|
|
l = args.l.lower()
|
2022-02-12 11:33:23 +00:00
|
|
|
# Look up the answer's index
|
2022-02-12 12:22:45 +00:00
|
|
|
if l in w.Answers and w.Answers.index(l) < d:
|
|
|
|
print ("Wordle {}: {}".format(w.Answers.index(l), l))
|
|
|
|
else:
|
2022-02-12 16:11:32 +00:00
|
|
|
print ("{} is not a Wordle (yet?)".format(args.l))
|
2022-02-12 11:33:23 +00:00
|
|
|
exit(0)
|
|
|
|
|
|
|
|
# d is for "Find this day's answer"
|
|
|
|
if args.d != None:
|
|
|
|
# Look up the answer
|
|
|
|
if args.d < len(w.Answers):
|
|
|
|
print (w.Answers[args.d])
|
|
|
|
else:
|
|
|
|
print ("No Solution")
|
|
|
|
exit(0)
|
|
|
|
|
2022-02-12 16:11:32 +00:00
|
|
|
# g is for "maximum guesses"
|
2022-02-12 12:22:45 +00:00
|
|
|
if args.g:
|
2022-02-12 16:45:33 +00:00
|
|
|
max_guesses = abs(args.g)
|
2022-02-12 12:22:45 +00:00
|
|
|
else:
|
|
|
|
max_guesses = 6
|
|
|
|
|
2022-02-12 11:33:23 +00:00
|
|
|
# Get today's word
|
2022-02-12 16:11:32 +00:00
|
|
|
if args.word:
|
|
|
|
wotd = args.word
|
|
|
|
# Indicate a non-standard word
|
|
|
|
d = -1
|
|
|
|
else:
|
|
|
|
if d >= len(w.Answers):
|
|
|
|
d = len(w.Answers) - 1
|
|
|
|
wotd = w.Answers[d]
|
2022-02-12 11:33:23 +00:00
|
|
|
|
|
|
|
# Box characters!
|
|
|
|
a = ["⬛", "🟨", "🟩"]
|
|
|
|
|
|
|
|
# Guesses go here
|
|
|
|
g = []
|
|
|
|
|
2022-02-12 12:22:45 +00:00
|
|
|
# Hits/Misses go here
|
|
|
|
h = ""
|
|
|
|
m = ""
|
|
|
|
|
2022-02-12 11:33:23 +00:00
|
|
|
# C R A N E
|
|
|
|
hints = [0, 0, 0, 0, 0]
|
|
|
|
|
|
|
|
def wordbox(word):
|
|
|
|
b = ""
|
2022-02-12 16:11:32 +00:00
|
|
|
global h, m, hints
|
2022-02-12 11:33:23 +00:00
|
|
|
wordlist = list(wotd)
|
2022-02-12 16:11:32 +00:00
|
|
|
|
|
|
|
line = [0] * len(word)
|
|
|
|
# Green pass
|
2022-02-12 11:33:23 +00:00
|
|
|
for i in range(len(word)):
|
|
|
|
if word[i] == wotd[i]:
|
2022-02-12 16:11:32 +00:00
|
|
|
line[i] = 2
|
2022-02-12 11:33:23 +00:00
|
|
|
hints[i] = 2
|
|
|
|
wordlist[i] = 0
|
2022-02-12 16:11:32 +00:00
|
|
|
|
|
|
|
# Yellow pass
|
|
|
|
for i in range(len(word)):
|
|
|
|
if word[i] in wordlist:
|
|
|
|
line[i] = 1
|
2022-02-12 11:33:23 +00:00
|
|
|
# Mark as hinted (wrong place)
|
|
|
|
hints[wordlist.index(word[i])]= 1
|
|
|
|
# Remove letter from wordlist
|
|
|
|
wordlist[wordlist.index(word[i])] = 0
|
2022-02-12 12:22:45 +00:00
|
|
|
# Mark the hit
|
|
|
|
h += word[i]
|
2022-02-12 16:11:32 +00:00
|
|
|
|
|
|
|
# Blockify pass
|
|
|
|
for i in line:
|
|
|
|
b += a[i]
|
2022-02-12 11:33:23 +00:00
|
|
|
print(b)
|
|
|
|
|
|
|
|
def game():
|
2022-02-12 12:22:45 +00:00
|
|
|
print("[ Wordle {}{} ]".format(d, "*" if args.hard else " "))
|
2022-02-12 11:33:23 +00:00
|
|
|
words = w.Words + w.Answers
|
|
|
|
guess = 0
|
2022-02-12 12:22:45 +00:00
|
|
|
while guess < max_guesses:
|
2022-02-12 12:26:48 +00:00
|
|
|
ui = input().lower()
|
2022-02-12 16:11:32 +00:00
|
|
|
if len(ui) == 5 and (ui in words or args.nonsense):
|
2022-02-12 11:33:23 +00:00
|
|
|
g.append(ui)
|
|
|
|
wordbox(ui)
|
|
|
|
if (ui == wotd):
|
|
|
|
win(True)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
guess += 1
|
|
|
|
else:
|
2022-02-12 12:22:45 +00:00
|
|
|
if ui == "exit":
|
|
|
|
exit()
|
2022-02-12 11:33:23 +00:00
|
|
|
print ("Not in word list")
|
|
|
|
win(False)
|
|
|
|
|
|
|
|
def win(won):
|
2022-02-12 12:22:45 +00:00
|
|
|
print("\nWordle {} {}/{}{}\n".format(d, len(g) if won else "X", max_guesses, "*" if args.hard else ""))
|
2022-02-12 11:33:23 +00:00
|
|
|
for gi in g:
|
|
|
|
wordbox(gi)
|
2022-02-12 16:11:32 +00:00
|
|
|
print()
|
2022-02-12 11:33:23 +00:00
|
|
|
game()
|