-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoviedle_cli.py
More file actions
32 lines (26 loc) · 1.15 KB
/
moviedle_cli.py
File metadata and controls
32 lines (26 loc) · 1.15 KB
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
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from model.candidation_types import TopNVoteCountCandidator
from model.moviedle_game import MoviedleGame
if __name__ == "__main__":
import config
engine = create_engine(config.DATABASE_URL, echo=config.DATABASE_VERBOSE_LOGGING)
with Session(engine) as session:
game = MoviedleGame(TopNVoteCountCandidator(10), session)
while not game.isGameOver:
try:
user_input = input("Enter your guessed movie titleid (or Ctrl+D to quit): ").strip()
except EOFError:
print("Exiting the game.")
break
try:
guess = game.make_guess(user_input)
print("Guess relations:")
for attr, relation in guess.guess_relations_dict.items():
print(f"\t{attr}: {relation.value}")
except Exception as e:
print(f"Error: {e}")
if game.isGameWon:
print("Congratulations! You've guessed the correct movie!")
print("Last guessed movie:", game.guesses[-1].movie.primarytitle, "(", game.guesses[-1].movie.titleid, ")")
print("Candidate movie:", game.candidateMovie.primarytitle, "(", game.candidateMovie.titleid, ")")