From 9a996b72854cbd1b929d69f0e70f4f877b8ad0e5 Mon Sep 17 00:00:00 2001 From: empathicqubit Date: Tue, 16 Mar 2021 11:54:54 -0500 Subject: [PATCH] Kill the run the instant the map screen gets loaded --- game.lua | 14 ++++++++++++++ neat-donk.lua | 12 ++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/game.lua b/game.lua index f0f821a..9240e45 100644 --- a/game.lua +++ b/game.lua @@ -401,14 +401,28 @@ function _M.onceAreaLoaded(handler) table.insert(areaLoadedQueue, handler) end +local mapLoadedQueue = {} +function _M.onceMapLoaded(handler) + -- TODO For now we only want one at a time + mapLoadedQueue = {} + table.insert(mapLoadedQueue, handler) +end + function processAreaLoad() for i=#areaLoadedQueue,1,-1 do table.remove(areaLoadedQueue, i)() end end +function processMapLoad() + for i=#mapLoadedQueue,1,-1 do + table.remove(mapLoadedQueue, i)() + end +end + function _M.registerHandlers() memory2.BUS:registerwrite(0xb517b2, processAreaLoad) + memory2.WRAM:registerread(0x06b1, processMapLoad) end return _M diff --git a/neat-donk.lua b/neat-donk.lua index 83fdbda..46de98b 100644 --- a/neat-donk.lua +++ b/neat-donk.lua @@ -662,6 +662,10 @@ function on_timer() end pool.currentFrame = 0 timeout = config.NeatConfig.TimeoutConstant + -- Kill the run if we go back to the map screen + game.onceMapLoaded(function() + timeout = -100000 + end) game.clearJoypad() startKong = game.getKong() startBananas = game.getBananas() @@ -942,11 +946,6 @@ function mainLoop (species, genome) timeout = timeout + 60 * 10 end - local lives = game.getLives() - if lives == 0 then - timeout = 0 - end - timeout = timeout - 1 -- Continue if we haven't timed out @@ -985,10 +984,11 @@ function mainLoop (species, genome) end most = most - pool.currentFrame / 2 end - local fitness = bananaCoinsFitness - hitPenalty + powerUpBonus + most + game.getJumpHeight() / 100 + local lives = game.getLives() + if startLives < lives then local ExtraLiveBonus = (lives - startLives)*1000 fitness = fitness + ExtraLiveBonus