File size: 1,082 Bytes
03b0d13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()