local WINDOW_WIDTH = 1200
local WINDOW_HEIGHT = 800
+local love = love or {}
function love.conf(t)
t.window.title = "Maching Learning Game"
return {
-- GENERAL PROPERTIES
- LOAD_FILE = "";
- SAVE_FILE = "./saved/POPULATION";
+ LOAD_FILE = "./saved/TERM_1_GEN_14";
+ SAVE_FILE = "./saved/TERM";
WINDOW_WIDTH = WINDOW_WIDTH;
WINDOW_HEIGHT = WINDOW_HEIGHT;
local Trainer = (require "src.trainer").Trainer
local World = world_mod.World
-local Enemy = world_mod.Enemy
local Wall = world_mod.Wall
local Population = Gen.Population
-local world, player
+local world
local input
local pop
local trainer
-local update_speed = 30
-
local ui_font
local fitness_font
local stored_fitnesses = {}
-local enemies = {}
function love.load()
math.randomseed(os.time())
- world, player = World.new()
- local enemy = Enemy.new(0, 0)
- table.insert(enemies, enemy)
- world:add_entity(enemy)
+ world = World.new()
local wall1 = Wall.new(-20, -20, 840, 20)
local wall2 = Wall.new(-20, 600, 840, 20)
end
function Trainer:initialize_training()
+ self.world:spawn_enemies(1)
+
self.population_step = self.population:start_training()
self.after_inputs_func = function(...)
return fitness, self.player.alive
end
-function Trainer:pre_evolution(_, _, _)
+function Trainer:pre_evolution(avg, high, _)
+ print("FINISHED GENERATION: " .. self.population.generation .. " | Stats: ")
+ print(" Average: " .. tostring(avg))
+ print(" Highest: " .. tostring(high))
+ print("--------------------------------------------------------------------")
end
function Trainer:post_evolution(_)
--- /dev/null
+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