diff --git a/pool.lua b/pool.lua index fb4ae75..efb0e80 100644 --- a/pool.lua +++ b/pool.lua @@ -732,7 +732,6 @@ local function mainLoop(currentSpecies, topGenome) table.insert(slice, pool.species[i]) end end - local finished = 0 return runner.run( slice, @@ -741,7 +740,11 @@ local function mainLoop(currentSpecies, topGenome) -- Genome callback -- FIXME Should we do something here??? What was your plan, past me? end - ):next(function() + ):next(function(maxFitness) + if maxFitness > pool.maxFitness then + pool.maxFitness = maxFitness + end + if hasThreads then currentSpecies = currentSpecies + #slice else diff --git a/runner-process.lua b/runner-process.lua index 4534cd2..8daf9f8 100644 --- a/runner-process.lua +++ b/runner-process.lua @@ -124,9 +124,10 @@ local function waitLoop(inputLine) speciesId = speciesId, }) end - ):next(function() + ):next(function(maxFitness) writeResponse({ type = 'onFinish', + maxFitness = maxFitness, speciesId = speciesId, }) end) diff --git a/runner-wrapper.lua b/runner-wrapper.lua index 85a7b29..129fc0c 100644 --- a/runner-wrapper.lua +++ b/runner-wrapper.lua @@ -174,6 +174,7 @@ return function(promise) message(_M, 'Waiting for child processes to finish') + local maxFitness = nil local function readLoop(outputPipe) return util.promiseWrap(function() return outputPipe:read("*l") @@ -210,12 +211,15 @@ return function(promise) end genomeCallback(obj.genome, obj.index) elseif obj.type == 'onFinish' then + if maxFitness == nil or obj.maxFitness > maxFitness then + maxFitness = obj.maxFitness + end return true end end):next(function(finished) if finished then - return + return maxFitness end return readLoop(outputPipe) @@ -230,8 +234,16 @@ return function(promise) end return Promise.all(table.unpack(waiters)) - end):next(function() + end):next(function(maxFitnesses) message(_M, 'Child processes finished') + local maxestFitness = maxFitnesses[1] + for i=1,#maxFitnesses,1 do + local maxFitness = maxFitnesses[i] + if maxFitness > maxestFitness then + maxestFitness = maxFitness + end + end + return maxestFitness end) end diff --git a/runner.lua b/runner.lua index c2ec7bf..3e2b2ca 100644 --- a/runner.lua +++ b/runner.lua @@ -578,7 +578,7 @@ local function mainLoop(_M, genome) _M.timeout = 0 end - if _M.currentFrame%5 == 0 then + if _M.currentFrame % 5 == 0 then local inputs, inputDeltas = game.getInputs() if game.bonusScreenDisplayed(inputs) and _M.timeout > -1000 and _M.timeout < timeoutConst then _M.timeout = timeoutConst @@ -639,7 +639,7 @@ local function mainLoop(_M, genome) -- Continue if we haven't timed out local timeoutBonus = _M.currentFrame / 4 - if _M.timeout + timeoutBonus > 0 then + if _M.timeout + timeoutBonus > 0 or _M.currentFrame % 5 ~= 0 then return mainLoop(_M, genome) end @@ -686,7 +686,7 @@ local function mainLoop(_M, genome) end genome.fitness = fitness - if fitness > _M.maxFitness then + if _M.maxFitness == nil or fitness > _M.maxFitness then _M.maxFitness = fitness end @@ -712,7 +712,7 @@ local function mainLoop(_M, genome) input.keyhook("9", false) input.keyhook("tab", false) - return + return _M.maxFitness end end @@ -910,7 +910,7 @@ return function(promise) currentGenomeIndex = 1, currentFrame = 0, drawFrame = 0, - maxFitness = 0, + maxFitness = nil, dereg = {}, inputmode = false,