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 w
|
||||||
|
import c
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
# Set up argument parser
|
# Set up argument parser
|
||||||
@ -20,7 +31,7 @@ parser.add_argument('--hard', action='store_true', help="enable hard m
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Handle the args
|
# Handle the args
|
||||||
# Get today's day number
|
# Get today's day number
|
||||||
if args.day is not None:
|
if args.day is not None:
|
||||||
# Ahoy-hoy, time traveller!
|
# Ahoy-hoy, time traveller!
|
||||||
d = args.day
|
d = args.day
|
||||||
@ -28,7 +39,7 @@ else:
|
|||||||
# find num. days since Wordle launch
|
# find num. days since Wordle launch
|
||||||
d = (date.today() - date(2021, 6, 19)).days
|
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()
|
l = args.l.lower()
|
||||||
# Look up the answer's index
|
# Look up the answer's index
|
||||||
@ -38,7 +49,7 @@ if args.l:
|
|||||||
print ("{} is not a Wordle (yet?)".format(args.l))
|
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"
|
||||||
if args.d != None:
|
if args.d != None:
|
||||||
# Look up the answer
|
# Look up the answer
|
||||||
if args.d < len(w.Answers):
|
if args.d < len(w.Answers):
|
||||||
@ -47,13 +58,13 @@ if args.d != None:
|
|||||||
print ("No Solution")
|
print ("No Solution")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
# g is for "maximum guesses"
|
# g is for "maximum guesses"
|
||||||
if args.g:
|
if args.g:
|
||||||
max_guesses = abs(args.g)
|
max_guesses = abs(args.g)
|
||||||
else:
|
else:
|
||||||
max_guesses = 6
|
max_guesses = 6
|
||||||
|
|
||||||
# Get today's word
|
# Get today's word
|
||||||
if args.word:
|
if args.word:
|
||||||
solution = args.word
|
solution = args.word
|
||||||
# Indicate a non-standard word
|
# Indicate a non-standard word
|
||||||
@ -71,11 +82,14 @@ else:
|
|||||||
|
|
||||||
# Box characters!
|
# Box characters!
|
||||||
boxes = ["⬛", "🟨", "🟩"]
|
boxes = ["⬛", "🟨", "🟩"]
|
||||||
|
# gray bg yellow bg green bg white fg black bg
|
||||||
|
colors= [0x13a3a3c, 0x1b59f3b, 0x1538d4e, 0xd7dadc, 0x1121213]
|
||||||
|
|
||||||
# Guesses go here
|
# Guesses go here
|
||||||
guesses = []
|
guesses = []
|
||||||
|
|
||||||
def wordbox(word):
|
# Letter is in boxes
|
||||||
|
def wordbox(word, showword = 0):
|
||||||
output = ""
|
output = ""
|
||||||
line = [0] * len(word)
|
line = [0] * len(word)
|
||||||
guess = list(word)
|
guess = list(word)
|
||||||
@ -95,28 +109,40 @@ def wordbox(word):
|
|||||||
# Remove letter from solution and guess
|
# Remove letter from solution and guess
|
||||||
sol[sol.index(word[i])] = guess[i] = 0
|
sol[sol.index(word[i])] = guess[i] = 0
|
||||||
# Turn blocks into a string, and print it
|
# Turn blocks into a string, and print it
|
||||||
for i in line:
|
if showword:
|
||||||
output += boxes[i]
|
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)
|
print(output)
|
||||||
|
|
||||||
def game():
|
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
|
words = w.Words + w.Answers
|
||||||
guess = 0
|
guess = 0
|
||||||
while guess < max_guesses:
|
while guess < max_guesses:
|
||||||
ui = input().lower()
|
# lol i should probably use curses
|
||||||
if len(ui) == 5 and (ui in words or args.nonsense):
|
user_input = input(" [ ]\b\b\b\b\b\b").lower()
|
||||||
guesses.append(ui)
|
if len(user_input) == 5 and (user_input in words or args.nonsense):
|
||||||
wordbox(ui)
|
# Add guesses to the guessed list, and put the word in boxes
|
||||||
if (ui == solution):
|
guesses.append(user_input)
|
||||||
|
wordbox(user_input, 1)
|
||||||
|
# win condition
|
||||||
|
if (user_input == solution):
|
||||||
win(True)
|
win(True)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
guess += 1
|
guess += 1
|
||||||
else:
|
else:
|
||||||
if ui == "exit":
|
# Allow the user to make it stop
|
||||||
|
if user_input == "exit":
|
||||||
exit()
|
exit()
|
||||||
print ("Not in word list")
|
print ("Not in word list")
|
||||||
|
# lose
|
||||||
win(False)
|
win(False)
|
||||||
|
|
||||||
def win(won):
|
def win(won):
|
||||||
|
Loading…
Reference in New Issue
Block a user