forked from vivek3141/super-mario-neat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
54 lines (48 loc) · 1.54 KB
/
run.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
import neat
import pickle
import gym, ppaquette_gym_super_mario
import visualize
import gzip
import neat.genome
ACTIONS = [
[0, 0, 0, 1, 0, 1],
[0, 0, 0, 1, 1, 1],
]
# FILENAME = "./Files/gen_2284"
CONFIG = 'config'
def main(config_file, file, level="1-1"):
# with gzip.open(FILENAME) as f:
# config = pickle.load(f)[1]
# print(str(config.genome_type.size))
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_file)
genome = pickle.load(open(file, 'rb'))
env = gym.make('ppaquette/SuperMarioBros-'+level+'-Tiles-v0')
net = neat.nn.FeedForwardNetwork.create(genome, config)
info = {'distance': 0}
try:
while info['distance'] != 3252:
state = env.reset()
done = False
i = 0
old = 40
while not done:
state = state.reshape(208)
output = net.activate(state)
ind = output.index(max(output))
s, reward, done, info = env.step(ACTIONS[ind])
state = s
i += 1
if i % 50 == 0:
if old == info['distance']:
break
else:
old = info['distance']
print("Distance: {}".format(info['distance']))
env.close()
except KeyboardInterrupt:
env.close()
exit()
if __name__ == "__main__":
main(CONFIG, "finisher.pkl")