-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpydle.py
303 lines (292 loc) · 10.7 KB
/
pydle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import random
from _vendor.termcolor import colored
from time import sleep
from os import system
playing = True
pydleText1 = colored("Welcome to ", "green")
pydleText2 = colored("pydle", "magenta")
pydleText3 = colored("!", "green")
print("\n---------------------\n" + pydleText1 + pydleText2 + pydleText3 +
"\n\nWordle, but in the terminal!\n---------------------\n\n")
sleep(1)
useless = input("Press enter to start, or type anything to change settings. ")
if useless != "":
print('What color scheme would you like to use?\nLeave blank to use the default, enter "custom" to choose any colors, or enter "colorblind" for a red and blue theme.')
colorScheme = input("Color scheme: ")
if colorScheme == "":
colorScheme = "wordle"
outline = False # Does not work when set to true
match colorScheme:
case "pydle":
colorCorrect = "green"
colorInWord = "magenta"
colorNone = ""
case "wordle" | "":
colorCorrect = "green"
colorInWord = "yellow"
colorNone = ""
case "alt":
colorCorrect = "cyan"
colorInWord = "blue"
colorNone = "white"
case "warm":
colorCorrect = "yellow"
colorInWord = "magenta"
colorNone = "red"
case "cold":
colorCorrect = "blue"
colorInWord = "cyan"
colorNone = "magenta"
case "simple":
colorCorrect = "white"
colorInWord = "cyan"
colorNone = ""
case "neon":
colorCorrect = "magenta"
colorInWord = "green"
colorNone = "cyan"
case "yellow":
colorCorrect = "red"
colorInWord = "white"
colorNone = "yellow"
case "colorblind":
colorCorrect = "blue"
colorInWord = "red"
colorNone = ""
case "colorblind2":
colorCorrect = "yellow"
colorInWord = "magenta"
colorNone = ""
case "hardMode":
colorCorrect = "red"
colorInWord = "red"
colorNone = ""
case "custom":
print("Valid colors: grey, red, green, yellow, blue, magenta, cyan, and white.\nYou will get an error if you do not enter any of these colors exactly.\n")
colorCorrect = input("Color when the letter is in the correct spot: ")
colorInWord = input(
"Color when the letter is in the word but in the wrong spot: ")
colorNone = input(
"Color when the letter is not in the word: ")
case _:
print("\n\n\n\n\n\n\n")
warningText = colored("ERROR", "red")
print("\n!!!\n" + warningText +
"\nInvalid color scheme.\n!!!\n")
quit()
if colorScheme != "":
if colorNone == "":
colorNone = "white"
print("Correct color - " + colored(colorCorrect, colorCorrect) + "\nIn word color - " +
colored(colorInWord, colorInWord) + "\nIncorrect color - " + colored(colorNone, colorNone))
print("\nHow many letters do you want to play with? 5 is the default.\n")
letterAmount = input("Number of letters: ")
if letterAmount == "":
letterAmount = 5
letterAmount = int(letterAmount)
if letterAmount == 1:
guessAmount = 16
if letterAmount == 2:
guessAmount = 11
elif letterAmount == 3:
guessAmount = 8
elif letterAmount == 4:
guessAmount = 5
elif letterAmount == 5:
guessAmount = 6
elif letterAmount == 6:
guessAmount = 11
elif letterAmount == 7:
guessAmount = 13
elif letterAmount == 8:
guessAmount = 20
elif letterAmount <= 25:
guessAmount = 99
else:
print("\n\n\n\n\n\n\n")
warningText = colored("ERROR", "red")
print("\n!!!\n" + warningText +
"\npydle only works with word length in range 1-25.\n!!!\n")
quit()
print("\nBased on the amount of letters, you will get " +
str(guessAmount) + " guesses.\n")
#extraInfo = input("(Yes or no) Would you like to display extra info? ")
extraInfo = False # Has some problems
# if "ye" in extraInfo or "True" in extraInfo:
# extraInfo = True
# else:
# extraInfo = False
delay = input(
"How long do you want the delay between revealing the letters in milliseconds? Leave blank for auto. ")
if delay == "":
delay = "auto"
# else:
# delay = int(delay)
useless = input("\nPress enter to start.")
else:
colorCorrect = "green"
colorInWord = "yellow"
colorNone = ""
colorScheme = "wordle"
guessAmount = 6
letterAmount = 5
outline = False
extraInfo = False
delay = "auto"
keyboard = "qwertyuiopasdfghjklzxcvbnm"
startKeyboard = "qwertyuiopasdfghjklzxcvbnm"
knownLetters = ""
if outline:
colorCorrect = "on_" + str(colorCorrect)
colorInWord = "on_" + str(colorInWord)
if letterAmount == 5:
with open("word_lists/wordle-list.txt") as file:
words = file.read().split("\n")
else:
filename = str(letterAmount) + "-list.txt"
with open(f"word_lists/{filename}") as file:
words = file.read().split("\n")
def insertSpace():
#print("\n" * 150)
system("clear")
def coolPrint(thing):
for i in thing:
print(i, end="")
sleep(0.2)
print("")
def coolerPrint(out):
insertSpace()
fullOutput.append(out)
for item in fullOutput:
print(item)
def update(out):
for item in fullOutput:
insertSpace()
print(item)
sleep(0.2)
while playing:
# answer = random.choice(words)
wordNum = random.randint(0, len(words) - 1)
answer = words[wordNum]
for character in answer:
knownLetters += "-"
guessNum = 0
fullOutput = []
additionalOutput = ""
emojis = ""
insertSpace()
for guessNum in range(guessAmount):
guess = input("Guess #" + str(guessNum + 1) + ": ").strip()
outList = []
output = ""
if len(guess) == letterAmount and guess in words:
for i in range(letterAmount):
if guess[i] == answer[i]:
outList.append("#")
emojis += "🟩"
elif guess[i] in answer:
emojis += "🟨"
outList.append("-")
else:
outList.append("-")
emojis += "⬛️"
outList2 = []
for symbol, letter in zip(outList, guess):
if symbol == "-":
countInGuess = 0
for symbol3, letter3 in zip(outList2, guess):
if symbol3 == "*" and letter3 == letter:
countInGuess += 1
countInAnswer = 0
for letter2, symbol2 in zip(answer, outList):
if letter2 == letter and not symbol2 == "#":
countInAnswer += 1
if countInAnswer > countInGuess:
outList2.append("*")
else:
outList2.append("-")
else:
outList2.append("#")
output = ""
print(outList2)
for letter, symbol in zip(guess, outList2):
if symbol == "#":
if not outline:
output += colored(letter, colorCorrect)
for letter4, letter5, letter6 in zip(knownLetters, guess, answer):
knownLetters = ""
if letter5 == letter6:
knownLetters += letter4
else:
knownLetters += "-"
for letter4, letter5, letter6, letter7 in zip(keyboard, guess, answer, startKeyboard):
keyboard = ""
if letter5 == letter6:
keyboard += colored(letter7, colorCorrect)
else:
keyboard += letter7
else:
output += colored(letter, white, colorCorrect)
if symbol == "*":
if not outline:
output += colored(letter, colorInWord)
else:
output += colored(letter, white, colorInWord)
for letter4, letter5, letter6, letter7 in zip(keyboard, guess, answer, startKeyboard):
keyboard = ""
if letter5 == letter6:
keyboard += colored(letter7, colorInWord)
else:
keyboard += letter7
if symbol == "-":
if colorNone == "":
output += letter
else:
if colorScheme == "" or colorScheme == "pydle":
output += str(letter)
else:
output += colored(letter, colorNone)
insertSpace()
print(output)
if delay == "auto":
sleep(1.5 / letterAmount)
elif delay == 0:
pass
else:
sleep(int(delay) / 1000)
insertSpace()
coolerPrint(output)
if extraInfo == True:
print("\n" + keyboard)
print("\n" + knownLetters)
emojis += "\n"
if str(guess).strip() == str(answer).strip():
print("Congrats! You got the word in " +
str(guessNum + 1) + " guesses!")
break
else:
if len(guess) == letterAmount:
coolerPrint(str(guess) + " is not a valid word.")
for guessCharacter in guess:
emojis += "🟥"
emojis += "\n"
else:
print("Please enter a " + str(letterAmount) + " letter word, not a " +
str(len(guess)) + " letter word.")
for guessCharacter in guess:
emojis += "🟥"
emojis += "\n"
# playing = False
# break
if not str(guess).strip() == str(answer).strip():
print("The word was " + answer + "!")
sleep(0.5)
print("Your result: \n")
print("pydle " + str(wordNum + 1) + " " +
str(guessNum + 1) + "/" + str(guessAmount))
print(emojis)
ask = input("\nPress enter to play again, type anything to quit. ")
if "" == ask:
playing = True
else:
playing = False