Added random play functionality

This commit is contained in:
xereeto 2024-03-09 18:07:34 +00:00
parent 384dc9296a
commit bf78959815
1 changed files with 11 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import time
from getch import getch from getch import getch
import possible import possible
import os import os
import random
term = blessed.Terminal() term = blessed.Terminal()
@ -123,6 +124,9 @@ class Wordle:
self.number = number self.number = number
self.turn = 0 self.turn = 0
self.curGuess="" self.curGuess=""
if 'random' in os.environ:
self.answer = random.choice(possible.answers).upper()
else:
self.answer = possible.answers[number].upper() self.answer = possible.answers[number].upper()
self.guessedKeys = {} self.guessedKeys = {}
# 0 = no guess, 1 = not in word, 2 = wrong place, 3 = correct # 0 = no guess, 1 = not in word, 2 = wrong place, 3 = correct
@ -261,6 +265,7 @@ def main():
time.sleep(2) time.sleep(2)
midnight = (datetime.datetime.now() + datetime.timedelta(days=1)).replace(hour=0, minute=0, microsecond=0, second=0) midnight = (datetime.datetime.now() + datetime.timedelta(days=1)).replace(hour=0, minute=0, microsecond=0, second=0)
w.updateError() w.updateError()
if not 'random' in os.environ:
w.updateError("Next WORDLE in: "+str(datetime.timedelta(seconds=(midnight-datetime.datetime.now()).seconds))) w.updateError("Next WORDLE in: "+str(datetime.timedelta(seconds=(midnight-datetime.datetime.now()).seconds)))
time.sleep(2) time.sleep(2)
w.updateError("Press any key to exit...") w.updateError("Press any key to exit...")
@ -280,16 +285,17 @@ except KeyboardInterrupt:
pass pass
finally: finally:
with term.fullscreen(): with term.fullscreen():
put(term.clear) put(reset+term.clear)
print(reset+"Goodbye!") print(reset+"Goodbye!")
#put("Goodbye!") #put("Goodbye!")
cliflag = sys.argv[1] if len(sys.argv) > 1 else '' cliflag = sys.argv[1] if len(sys.argv) > 1 else ''
if(w and cliflag != "--no-unicode" and unicode): if(w and cliflag != "--no-unicode" and unicode):
print("\n\nWordle "+str(w.turn)+"/6") print("\n\nWordle "+("RANDOM" if 'random' in os.environ else str(w.number))+" "+(str(w.turn) if w.wonGame() else "X")+"/6\n")
blocks=["","🟨","🟩"] blocks=["","🟨","🟩"]
for guess in w.guesses: for guess in w.guesses:
if guess[0][0]: if guess[0][0]:
for letter in guess[0]: for letter in guess[0]:
put(blocks[letter-1]) put(blocks[letter-1])
print() print()
print("\n"+term.underline("play in terminal")+"\ntoday's WORDLE: $ ssh play@wordle.xereeto.co.uk -p 9999\nrandom WORDLE: $ ssh play-random@wordle.xereeto.co.uk -p 9999")