-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagent.py
67 lines (50 loc) · 1.59 KB
/
agent.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import random
from lux.game import Game
from qlara import QLara
configuration = {
'lr': 0.01,
'gamma': 0.9,
'epsilon': 0.9,
'epsilon_final': 0.5,
'epsilon_decay': 0.995,
'batch_length': 1,
'epochs': 0,
'episodes': 0
}
episodes = configuration.pop('episodes')
qlara = QLara(**configuration)
def agent(observation):
global game_state, clara
### Do not edit ###
if observation["step"] == 0:
game_state = Game()
game_state._initialize(observation["updates"])
game_state._update(observation["updates"][2:])
game_state.id = observation.player
qlara._model.load('qlara/models')
qlara.init_memory(game_state, observation)
actions = []
else:
game_state._update(observation["updates"])
### AI Code goes down here! ###
actions = qlara.play(game_state, observation)
return actions
if __name__ == '__main__':
import json
import random
from kaggle_environments import make
from IPython.display import clear_output
for ep in range(episodes):
clear_output()
print(f"=== Episode {ep} ===")
env = make("lux_ai_2021",
configuration={"seed": random.randint(0, 99999999),
"loglevel": 1,
"annotations": True},
debug=True)
steps = env.run([agent, "simple_agent"])
print([step[0]['action'] for step in steps])
clara._model.save('models')
replay = env.toJSON()
with open("replay.json", "w") as f:
json.dump(replay, f)