-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake_test_bfs.py
43 lines (34 loc) · 1005 Bytes
/
snake_test_bfs.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
import gym
import gym_snake
import numpy as np
from simple_snake_grid import SimpleSnakeGrid
np.set_printoptions(threshold=np.inf)
# Construct Environment
env = gym.make('snake-v0',grid_size=[8,8], unit_size=1,unit_gap=0,snake_size=2)
observation = env.reset() # Constructs an instance of the game
snake_grid = SimpleSnakeGrid(observation)
# BFS
while True:
snake_grid.update_observation(observation)
snake_grid.print_grid()
actions = snake_grid.bfs_actions()
if not actions:
break
for action in actions:
env.render()
observation, _, done, _ = env.step(action) # take bfs actions
if done:
env.render()
break
# try random actions
# for _ in range(100):
# env.render()
# action = env.action_space.sample()
# print(action)
# observation, reward, done, info = env.step(action) # take a random action
# # print(info)
# if done:
# break
# # bfs search
# curr_pos = get_snake_head(observation)
env.close()