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
|
return inputs, inputDeltaDistance
|
||||||
end
|
end
|
||||||
|
|
||||||
_M.areaLoadedQueue = {}
|
|
||||||
function _M.onceAreaLoaded(handler)
|
|
||||||
table.insert(_M.areaLoadedQueue, handler)
|
|
||||||
end
|
|
||||||
|
|
||||||
function _M.clearJoypad()
|
function _M.clearJoypad()
|
||||||
for b = 1,#config.ButtonNames do
|
for b = 1,#config.ButtonNames do
|
||||||
input.set(0, b - 1, 0)
|
input.set(0, b - 1, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local areaLoadedQueue = {}
|
||||||
|
function _M.onceAreaLoaded(handler)
|
||||||
|
table.insert(areaLoadedQueue, handler)
|
||||||
|
end
|
||||||
|
|
||||||
function processAreaLoad()
|
function processAreaLoad()
|
||||||
for i=#_M.areaLoadedQueue,1,-1 do
|
for i=#areaLoadedQueue,1,-1 do
|
||||||
table.remove(_M.areaLoadedQueue, i)()
|
table.remove(areaLoadedQueue, i)()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
memory2.BUS:registerwrite(0xb517b2, processAreaLoad)
|
function _M.registerHandlers()
|
||||||
|
memory2.BUS:registerwrite(0xb517b2, processAreaLoad)
|
||||||
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
@ -9,6 +9,8 @@ local game = dofile(base.."/game.lua")
|
||||||
local mathFunctions = dofile(base.."/mathFunctions.lua")
|
local mathFunctions = dofile(base.."/mathFunctions.lua")
|
||||||
local util = dofile(base.."/util.lua")
|
local util = dofile(base.."/util.lua")
|
||||||
|
|
||||||
|
game.registerHandlers()
|
||||||
|
|
||||||
loadRequested = false
|
loadRequested = false
|
||||||
saveRequested = false
|
saveRequested = false
|
||||||
lastBoth = 0
|
lastBoth = 0
|
||||||
|
@ -855,19 +857,26 @@ function mainLoop (species, genome)
|
||||||
|
|
||||||
timeout = timeout - 1
|
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 krem = game.getKremCoins() - startKrem
|
||||||
local kong = game.getKong()
|
|
||||||
|
|
||||||
if krem > lastKrem then
|
if krem > lastKrem then
|
||||||
lastKrem = krem
|
lastKrem = krem
|
||||||
timeout = timeoutConst + 60 * 5
|
timeout = timeoutConst + 60 * 5
|
||||||
end
|
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))
|
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)
|
local bananaCoinsFitness = (krem * 100) + (kong * 60) + (bananas * 50) + (coins * 0.2)
|
||||||
|
@ -926,10 +935,6 @@ function mainLoop (species, genome)
|
||||||
initializeRun(function()
|
initializeRun(function()
|
||||||
mainLoop(species, genome)
|
mainLoop(species, genome)
|
||||||
end)
|
end)
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
mainLoop(species, genome)
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue