-
Notifications
You must be signed in to change notification settings - Fork 1
/
watch_model.py
46 lines (33 loc) · 1.21 KB
/
watch_model.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
from game import Game
from game import Renderer
from joblib import load
from time import time
from sys import argv
from os import path
def main():
model_path = "./sample_models/FFDNN_2Layers.joblib"
if len(argv) > 1 and path.exists(argv[1]):
model_path = argv[1]
model, game_args = load(model_path)
renderer = Renderer()
game = Game(**game_args, view_size=model.view)
renderer.new_game_setup(game)
while renderer.running:
keys, req = renderer.get_input()
# Check if user is trying to restart / generate new game
if req in [renderer.RESTART, renderer.NEW_GAME]:
game_args['seed'] = game_args['seed'] if req == renderer.RESTART else int(time())
game = Game(**game_args, view_size=model.view)
renderer.new_game_setup(game)
continue
player_view = game.get_player_view()
keys = model.evaluate(player_view)
game.update(keys)
if game.game_over:
print(f"{game.player.fitness}")
game = Game(**game_args, view_size=model.view)
renderer.new_game_setup(game)
continue
renderer.draw_state(game, keys)
if __name__ == "__main__":
main()