| import model | |
| import tetris | |
| import representation | |
| from pathlib import Path | |
| script_dir = Path(__file__).parent.resolve() | |
| checkpoints_dir = script_dir / "checkpoints" | |
| checkpoints_dir.mkdir(parents=True, exist_ok=True) | |
| checkpoint_filename = "checkpoint14.pth" | |
| save_path = checkpoints_dir / checkpoint_filename | |
| # If you need it as a standard Python string: | |
| save_path_str = str(save_path) | |
| tai = model.TetrisAI(save_path) | |
| while True: | |
| gs = tetris.GameState() | |
| while True: | |
| print("Board:") | |
| print(str(gs)) | |
| # get move | |
| predictions:list[float] = tai.predict(representation.BoardState(gs)) | |
| shift:int = predictions.index(max(predictions)) | |
| print("Move: " + str(shift)) | |
| input("Enter to execute the move it selected: ") | |
| # make move | |
| gs.drop(shift) | |
| # if game over | |
| if gs.over(): | |
| print(str(gs)) | |
| print("Game is over!") | |
| print("Final score: " + str(gs.score())) | |
| print("Going to next game...") | |
| gs = tetris.GameState() | |
| gs.randomize() | |