pydle.py 12 KB

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