-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHumanvsAI_test_battle2.py
More file actions
85 lines (67 loc) · 2.05 KB
/
Copy pathHumanvsAI_test_battle2.py
File metadata and controls
85 lines (67 loc) · 2.05 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
## Static Imports
import os
import importlib
import gym
import gym_everglades
import pdb
import sys
import numpy as np
from everglades_server import server
from everglades_server import generate_map
## Input Variables
# Agent files must include a class of the same name with a 'get_action' function
# Do not include './' in file path
if len(sys.argv) > 1:
agent0_file = 'agents/' + sys.argv[1]
else:
agent0_file = 'agents/human_actions'
if len(sys.argv) > 2:
agent1_file = 'agents/' + sys.argv[2]
else:
agent1_file = 'agents/random_actions'
if len(sys.argv) > 3:
map_name = sys.argv[3] + '.json'
else:
map_name = 'DemoMap.json'
if map_name == 'RandomMap.json':
generate_map.exec(3)
config_dir = '/everglades/config/'
map_file = config_dir + map_name
setup_file = config_dir + 'GameSetup.json'
unit_file = config_dir + 'UnitDefinitions.json'
output_dir = '/everglades/game_telemetry/'
debug = True
## Specific Imports
agent0_name, agent0_extension = os.path.splitext(agent0_file)
agent0_mod = importlib.import_module(agent0_name.replace('/','.'))
agent0_class = getattr(agent0_mod, os.path.basename(agent0_name))
agent1_name, agent1_extension = os.path.splitext(agent1_file)
agent1_mod = importlib.import_module(agent1_name.replace('/','.'))
agent1_class = getattr(agent1_mod, os.path.basename(agent1_name))
## Main Script
env = gym.make('everglades-v0')
players = {}
names = {}
players[0] = agent0_class(env.num_actions_per_turn, 0, map_name)
names[0] = agent0_class.__name__
players[1] = agent1_class(env.num_actions_per_turn, 1, map_name)
names[1] = agent1_class.__name__
observations = env.reset(
players=players,
config_dir = config_dir,
map_file = map_file,
unit_file = unit_file,
output_dir = output_dir,
pnames = names,
debug = debug
)
actions = {}
## Game Loop
done = 0
while not done:
if debug:
env.game.debug_state()
for pid in players:
actions[pid] = players[pid].get_action( observations[pid] )
observations, reward, done, info = env.step(actions)
print(reward)