-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.lua
43 lines (34 loc) · 993 Bytes
/
train.lua
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
local CONF = require "conf"
local world_mod = require "src.world"
local Input = require "src.input"
local Gen = require "src.genetics"
require "src.data"
local Trainer = (require "src.trainer").Trainer
local World = world_mod.World
local Wall = world_mod.Wall
local Population = Gen.Population
local world, input, pop, trainer
math.randomseed(os.time())
world = World.new()
local wall1 = Wall.new(-20, -20, 840, 20)
local wall2 = Wall.new(-20, 600, 840, 20)
local wall3 = Wall.new(-20, 0, 20, 600)
local wall4 = Wall.new(800, 0, 20, 600)
world:add_entity(wall1)
world:add_entity(wall2)
world:add_entity(wall3)
world:add_entity(wall4)
input = Input:new()
if CONF.LOAD_FILE == "" then
pop = Population.new()
pop:create_genomes(CONF.POPULATION_SIZE, 16, 8)
else
pop = Population.load(CONF.LOAD_FILE)
end
trainer = Trainer.new(pop, world, input)
trainer:initialize_training()
trainer.max_speed = 360
trainer:change_speed(360)
while pop.generation <= 100 do
trainer:update(1 / 60)
end