g:
- (c) notice - colorful text - use wordbox to print letters in boxes - better(?) formatting on printed strings - use more descriptive variable names
This commit is contained in:
parent
1b214b33f0
commit
5cfd666654
58
src/g.py
58
src/g.py
@ -1,6 +1,17 @@
|
||||
"""
|
||||
Copyright(c) 2022 SoftFish
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
|
||||
import w
|
||||
import c
|
||||
import argparse
|
||||
import sys
|
||||
from datetime import date
|
||||
|
||||
# Set up argument parser
|
||||
@ -20,7 +31,7 @@ parser.add_argument('--hard', action='store_true', help="enable hard m
|
||||
args = parser.parse_args()
|
||||
|
||||
# Handle the args
|
||||
# Get today's day number
|
||||
# Get today's day number
|
||||
if args.day is not None:
|
||||
# Ahoy-hoy, time traveller!
|
||||
d = args.day
|
||||
@ -28,7 +39,7 @@ 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:
|
||||
l = args.l.lower()
|
||||
# Look up the answer's index
|
||||
@ -38,7 +49,7 @@ if args.l:
|
||||
print ("{} is not a Wordle (yet?)".format(args.l))
|
||||
exit(0)
|
||||
|
||||
# d is for "Find this day's answer"
|
||||
# d is for "Find this day's answer"
|
||||
if args.d != None:
|
||||
# Look up the answer
|
||||
if args.d < len(w.Answers):
|
||||
@ -47,13 +58,13 @@ if args.d != None:
|
||||
print ("No Solution")
|
||||
exit(0)
|
||||
|
||||
# g is for "maximum guesses"
|
||||
# g is for "maximum guesses"
|
||||
if args.g:
|
||||
max_guesses = abs(args.g)
|
||||
else:
|
||||
max_guesses = 6
|
||||
|
||||
# Get today's word
|
||||
# Get today's word
|
||||
if args.word:
|
||||
solution = args.word
|
||||
# Indicate a non-standard word
|
||||
@ -71,11 +82,14 @@ else:
|
||||
|
||||
# Box characters!
|
||||
boxes = ["⬛", "🟨", "🟩"]
|
||||
# gray bg yellow bg green bg white fg black bg
|
||||
colors= [0x13a3a3c, 0x1b59f3b, 0x1538d4e, 0xd7dadc, 0x1121213]
|
||||
|
||||
# Guesses go here
|
||||
guesses = []
|
||||
|
||||
def wordbox(word):
|
||||
# Letter is in boxes
|
||||
def wordbox(word, showword = 0):
|
||||
output = ""
|
||||
line = [0] * len(word)
|
||||
guess = list(word)
|
||||
@ -95,28 +109,40 @@ def wordbox(word):
|
||||
# Remove letter from solution and guess
|
||||
sol[sol.index(word[i])] = guess[i] = 0
|
||||
# Turn blocks into a string, and print it
|
||||
for i in line:
|
||||
output += boxes[i]
|
||||
if showword:
|
||||
for i in range(len(word)):
|
||||
#output += c.c(7,0,1) + (c.c(2,1) if line[i] == 2 else c.c(3,1) if line[i] == 1 else c.c(0,1,1)) + word[i].upper() + " " + c.reset
|
||||
output += c.c24(colors[3]) + c.c24(colors[line[i]]) + " " + word[i].upper() + " " + c.reset
|
||||
else:
|
||||
for i in line:
|
||||
#output += c.c(7, 0, 1) + (c.c(2, 1) if i == 2 else c.c(3, 1) if i == 1 else c.c(0, 1, 1)) + boxes[i] + c.reset
|
||||
output += c.c24(colors[3]) + c.c24(colors[i]) + boxes[i] + c.reset
|
||||
print(output)
|
||||
|
||||
def game():
|
||||
print("[ Wordle {}{} ]".format(d, "*" if args.hard else " "))
|
||||
spaces = " " * (2-(len(str(d))//2))
|
||||
print(c.reset + "[ " + spaces + "Wordle {}{}".format(d, "*" if args.hard else " ") + spaces + "]")
|
||||
words = w.Words + w.Answers
|
||||
guess = 0
|
||||
while guess < max_guesses:
|
||||
ui = input().lower()
|
||||
if len(ui) == 5 and (ui in words or args.nonsense):
|
||||
guesses.append(ui)
|
||||
wordbox(ui)
|
||||
if (ui == solution):
|
||||
# lol i should probably use curses
|
||||
user_input = input(" [ ]\b\b\b\b\b\b").lower()
|
||||
if len(user_input) == 5 and (user_input in words or args.nonsense):
|
||||
# Add guesses to the guessed list, and put the word in boxes
|
||||
guesses.append(user_input)
|
||||
wordbox(user_input, 1)
|
||||
# win condition
|
||||
if (user_input == solution):
|
||||
win(True)
|
||||
return
|
||||
else:
|
||||
guess += 1
|
||||
else:
|
||||
if ui == "exit":
|
||||
# Allow the user to make it stop
|
||||
if user_input == "exit":
|
||||
exit()
|
||||
print ("Not in word list")
|
||||
# lose
|
||||
win(False)
|
||||
|
||||
def win(won):
|
||||
|
Loading…
Reference in New Issue
Block a user