pydle.py 11 KB

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