-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_visualization.py
More file actions
42 lines (34 loc) · 1.39 KB
/
game_visualization.py
File metadata and controls
42 lines (34 loc) · 1.39 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
33
34
35
36
37
38
39
40
41
42
# script to visualize how agent plays a game
# useful to study different iterations
import numpy as np
from agent import DeepQLearningAgent
from game_environment import Snake
from utils import visualize_game
import json
# Using the same version as in training
version = 'v17.1'
with open('model_config/{:s}.json'.format(version), 'r') as f:
m = json.loads(f.read())
board_size = m['board_size']
frames = m['frames'] # keep frames >= 2
max_time_limit = m['max_time_limit']
supervised = bool(m['supervised'])
n_actions = m['n_actions']
obstacles = bool(m['obstacles'])
iteration_list = [107500, 119500]
max_time_limit = 398
# Initialize environment
env = Snake(board_size=board_size, frames=frames, max_time_limit=max_time_limit,
obstacles=obstacles, version=version)
s = env.reset()
n_actions = env.get_num_actions()
# Initialize the Agent
agent = DeepQLearningAgent(board_size=board_size, frames=frames,
n_actions=n_actions, buffer_size=10, version=version)
# Visualize the agent playing the game with weights from listed iterations
for iteration in iteration_list:
agent.load_model(file_path='models/{:s}'.format(version), iteration=iteration)
for i in range(5):
visualize_game(env, agent,
path='images/game_visual_{:s}_{:d}_14_ob_{:d}.mp4'.format(version, iteration, i),
debug=False, animate=True, fps=12)