-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_natselect.py
45 lines (30 loc) · 953 Bytes
/
main_natselect.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
"""
Tetris in Python for Natural Selection
"""
from nat_selection.agent import Agent as NatAgent
from nat_selection.model import Model
import time
from enviorment.tetris import Tetris
env = Tetris({'reduced_grid': 0, 'reduced_shapes': 0}, 'Genetic algorithm')
def main():
agent = NatAgent(cores=4)
generations = 1000
#candidate = agent.train(generations)
candidate = Model([-0.8995652940240592, 0.06425443268253492, -0.3175211096545741, -0.292974392382306])
while True:
score = 0
state, reward, done, info = env.reset()
while not done:
action = candidate.best(env)
for a in action:
env.render()
#time.sleep(0.1)
state, reward, done, info = env.step(a)
score += reward
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
finally:
env.quit()