-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
49 lines (44 loc) · 1.54 KB
/
main.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
import random
from backend import QuantumWordle
file_path = "valid-wordle-words.txt" # Credit: https://github.com/Kinkelin/WordleCompetition/edit/main/data/official/shuffled_real_wordles.txt
def choose_random_word(file_path):
""" Chooses random word from text file. """
try:
with open(file_path, 'r') as file:
words = file.readlines()
words = [word.strip() for word in words if word.strip()]
return random.choice(words) if words else None
except FileNotFoundError:
print(f"Error: The file '{file_path}' was not found.")
return None
""" Create game with hidden word. """
hidden_word = choose_random_word(file_path)
game = QuantumWordle(hidden_word)
""" Gameplay logic. """
status = False
attempts = 0
while(True):
if attempts == 6:
print("Game over!")
break
else:
if attempts > 1:
print(f"{6 - attempts} guesses remaining")
else:
print(f"{6 - attempts} guess remaining")
while True:
try:
guess = input("Enter guess: ")
if len(guess) != 5:
raise ValueError("Guess must be 5 letters long!")
if not guess.isalpha():
raise ValueError("Guess must contain only letters!")
break
except ValueError as e:
print(e)
guess = guess.upper()
status = game.guess(guess)
if status == True:
break
attempts+=1
print(f"Hidden word was {hidden_word}")