Long if blocks make my brain hurt
This commit is contained in:
parent
d0d7b71054
commit
9c0c1014c0
2 changed files with 86 additions and 79 deletions
18
game.lua
18
game.lua
|
@ -369,23 +369,25 @@ function _M.getInputs()
|
|||
return inputs, inputDeltaDistance
|
||||
end
|
||||
|
||||
_M.areaLoadedQueue = {}
|
||||
function _M.onceAreaLoaded(handler)
|
||||
table.insert(_M.areaLoadedQueue, handler)
|
||||
end
|
||||
|
||||
function _M.clearJoypad()
|
||||
for b = 1,#config.ButtonNames do
|
||||
input.set(0, b - 1, 0)
|
||||
end
|
||||
end
|
||||
|
||||
local areaLoadedQueue = {}
|
||||
function _M.onceAreaLoaded(handler)
|
||||
table.insert(areaLoadedQueue, handler)
|
||||
end
|
||||
|
||||
function processAreaLoad()
|
||||
for i=#_M.areaLoadedQueue,1,-1 do
|
||||
table.remove(_M.areaLoadedQueue, i)()
|
||||
for i=#areaLoadedQueue,1,-1 do
|
||||
table.remove(areaLoadedQueue, i)()
|
||||
end
|
||||
end
|
||||
|
||||
memory2.BUS:registerwrite(0xb517b2, processAreaLoad)
|
||||
function _M.registerHandlers()
|
||||
memory2.BUS:registerwrite(0xb517b2, processAreaLoad)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
@ -9,6 +9,8 @@ local game = dofile(base.."/game.lua")
|
|||
local mathFunctions = dofile(base.."/mathFunctions.lua")
|
||||
local util = dofile(base.."/util.lua")
|
||||
|
||||
game.registerHandlers()
|
||||
|
||||
loadRequested = false
|
||||
saveRequested = false
|
||||
lastBoth = 0
|
||||
|
@ -855,19 +857,26 @@ function mainLoop (species, genome)
|
|||
|
||||
timeout = timeout - 1
|
||||
|
||||
local timeoutBonus = pool.currentFrame / 4
|
||||
if timeout + timeoutBonus <= 0 then
|
||||
|
||||
local bananas = game.getBananas() - startBananas
|
||||
local coins = game.getCoins() - startCoins
|
||||
local krem = game.getKremCoins() - startKrem
|
||||
local kong = game.getKong()
|
||||
|
||||
if krem > lastKrem then
|
||||
lastKrem = krem
|
||||
timeout = timeoutConst + 60 * 5
|
||||
end
|
||||
|
||||
-- Continue if we haven't timed out
|
||||
local timeoutBonus = pool.currentFrame / 4
|
||||
if timeout + timeoutBonus > 0 then
|
||||
mainLoop(species, genome)
|
||||
return
|
||||
end
|
||||
|
||||
-- Timeout calculations beyond this point
|
||||
-- Manipulating the timeout value won't have
|
||||
-- any effect
|
||||
local bananas = game.getBananas() - startBananas
|
||||
local coins = game.getCoins() - startCoins
|
||||
local kong = game.getKong()
|
||||
|
||||
print(string.format("Bananas: %d, coins: %d, Krem: %d, KONG: %d", bananas, coins, krem, kong))
|
||||
|
||||
local bananaCoinsFitness = (krem * 100) + (kong * 60) + (bananas * 50) + (coins * 0.2)
|
||||
|
@ -926,10 +935,6 @@ function mainLoop (species, genome)
|
|||
initializeRun(function()
|
||||
mainLoop(species, genome)
|
||||
end)
|
||||
return
|
||||
end
|
||||
|
||||
mainLoop(species, genome)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue