-
Notifications
You must be signed in to change notification settings - Fork 173
/
optimization_dummy.py
60 lines (43 loc) · 1.79 KB
/
optimization_dummy.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
###############################################################################
# EvoMan FrameWork - V1.0 2016 #
# DEMO : Neuroevolution - Genetic Algorithm neural network. #
# Author: Karine Miras #
###############################################################################
# imports framework
import sys
from evoman.environment import Environment
from demo_controller import player_controller
# imports other libs
import numpy as np
import os
# runs simulation
def simulation(env,x):
f,p,e,t = env.play(pcont=x)
return f
# evaluation
def evaluate(env, x):
return np.array(list(map(lambda y: simulation(env,y), x)))
def main():
# choose this for not using visuals and thus making experiments faster
headless = True
if headless:
os.environ["SDL_VIDEODRIVER"] = "dummy"
experiment_name = 'optimization_test'
if not os.path.exists(experiment_name):
os.makedirs(experiment_name)
n_hidden_neurons = 10
# initializes simulation in individual evolution mode, for single static enemy.
env = Environment(experiment_name=experiment_name,
enemies=[2],
playermode="ai",
player_controller=player_controller(n_hidden_neurons), # you can insert your own controller here
enemymode="static",
level=2,
speed="fastest",
visuals=False)
# number of weights for multilayer with 10 hidden neurons
n_vars = (env.get_num_sensors()+1)*n_hidden_neurons + (n_hidden_neurons+1)*5
# start writing your own code from here
if __name__ == '__main__':
main()