From 515a6504ba0f892c3d5e67354a0e9925150c0925 Mon Sep 17 00:00:00 2001 From: empathicqubit Date: Sat, 6 Mar 2021 11:46:39 -0500 Subject: [PATCH] Have separate rightmost/upmost stats per screen --- donkutil.lua | 8 ++++++-- game.lua | 19 +++++++++++++++++++ neat-donk.lua | 47 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/donkutil.lua b/donkutil.lua index a69878e..0279418 100644 --- a/donkutil.lua +++ b/donkutil.lua @@ -14,6 +14,8 @@ DIDDY_X_VELOCITY = 0x7e0e02 DIDDY_Y_VELOCITY = 0x7e0e06 DIXIE_X_VELOCITY = 0x7e0e60 DIXIE_Y_VELOCITY = 0x7e0e64 +STAGE_NUMBER = 0x7e08a8 +STAGE_NUMBER_MOVEMENT = 0x7e08c8 CAMERA_X = 0x7e17ba CAMERA_Y = 0x7e17c0 CAMERA_MODE = 0x7e054f @@ -256,9 +258,11 @@ Sprite Details: %s camera %d,%d Vertical: %s Tile offset: %04x -]], direction, cameraX, cameraY, vertical, partyTileOffset) +Stage number: %04x +Stage (movement): %04x +]], direction, cameraX, cameraY, vertical, partyTileOffset, memory.readword(STAGE_NUMBER), memory.readword(STAGE_NUMBER_MOVEMENT)) - text(guiWidth - 200, guiHeight - 60, stats) + text(guiWidth - 200, guiHeight - 100, stats) text((partyX - 256 - cameraX) * 2, (partyY - 256 - cameraY) * 2 + 20, "Party") diff --git a/game.lua b/game.lua index 6fbdaf8..c3c80ca 100644 --- a/game.lua +++ b/game.lua @@ -23,6 +23,8 @@ SOLID_LESS_THAN = 0x7e00a0 KONG_LETTERS = 0x7e0902 MATH_LIVES = 0x7e08be DISPLAY_LIVES = 0x7e0c0 +MAIN_AREA_NUMBER = 0x7e08a8 +CURRENT_AREA_NUMBER = 0x7e08c8 function _M.getPositions() leader = memory.readword(LEAD_CHAR) @@ -200,6 +202,10 @@ function _M.getTile(dx, dy) return 1 end +function _M.getCurrentArea() + return memory.readword(CURRENT_AREA_NUMBER) +end + function _M.getJumpHeight() local sprite = _M.getSprite(leader) return sprite.jumpHeight @@ -353,10 +359,23 @@ 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 +function processAreaLoad() + for i=#_M.areaLoadedQueue,1,-1 do + table.remove(_M.areaLoadedQueue, i)() + end +end + +memory2.BUS:registerwrite(0xb517b2, processAreaLoad) + return _M diff --git a/neat-donk.lua b/neat-donk.lua index a5cd2a8..c8e4ca2 100644 --- a/neat-donk.lua +++ b/neat-donk.lua @@ -12,7 +12,6 @@ local util = dofile(base.."/util.lua") loadRequested = false saveRequested = false -kong = 0 lastBoth = 0 form = nil netPicture = nil @@ -661,8 +660,6 @@ function on_timer() if config.StartPowerup ~= NIL then game.writePowerup(config.StartPowerup) end - rightmost = 0 - upmost = 0 pool.currentFrame = 0 timeout = config.NeatConfig.TimeoutConstant game.clearJoypad() @@ -672,6 +669,10 @@ function on_timer() partyHitCounter = 0 powerUpCounter = 0 powerUpBefore = game.getBoth() + currentArea = game.getCurrentArea() + lastArea = currentArea + rightmost = { [currentArea] = 0 } + upmost = { [currentArea] = 0 } local species = pool.species[pool.currentSpecies] local genome = species.genomes[pool.currentGenome] generateNetwork(genome) @@ -803,19 +804,33 @@ function mainLoop (species, genome) -- Don't punish being launched by barrels -- FIXME Will this skew mine cart levels? if game.getVelocityY() < -1850 then - statusLine = string.format("Gotta go fast!!! %d", partyX) - statusColor = 0x0000ff00 timeout = timeoutConst + 60 * 2 end + local nextArea = game.getCurrentArea() + if nextArea ~= lastArea then + lastArea = nextArea + game.onceAreaLoaded(function() + statusLine = string.format("Area changed: %02x", currentArea) + statusColor = 0x00009900 + timeout = timeoutConst + 60 * 2 + currentArea = nextArea + lastArea = currentArea + if rightmost[currentArea] == nil then + rightmost[currentArea] = 0 + upmost[currentArea] = 0 + end + end) + end + if not vertical then - if partyX > rightmost then - rightmost = partyX + if partyX > rightmost[currentArea] then + rightmost[currentArea] = partyX timeout = timeoutConst end else - if partyY > upmost then - upmost = partyY + if partyY > upmost[currentArea] then + upmost[currentArea] = partyY timeout = timeoutConst end end @@ -862,9 +877,15 @@ function mainLoop (species, genome) local most = 0 if not vertical then - most = rightmost - pool.currentFrame / 2 + for k,v in pairs(rightmost) do + most = most + v + end + most = most - pool.currentFrame / 2 else - most = upmost - pool.currentFrame / 2 + for k,v in pairs(upmost) do + most = most + v + end + most = most - pool.currentFrame / 2 end @@ -877,10 +898,12 @@ function mainLoop (species, genome) end -- FIXME sus + --[[ if rightmost > 4816 then fitness = fitness + 1000 print("!!!!!!Beat level!!!!!!!") end + -- ]] if fitness == 0 then fitness = -1 end @@ -1212,6 +1235,8 @@ function displayForm() gui.text(130, 80, "Lives: " .. game.getLives()) gui.text(230, 65, "Damage: " .. partyHitCounter) gui.text(230, 80, "PowerUp: " .. powerUpCounter) + gui.text(320, 65, string.format("Current Area: %04x", currentArea)) + gui.text(320, 80, "Rightmost: "..rightmost[currentArea]) gui.rectangle(0, 100, 500, 50, 1, 0x000000000, 0x00990099) gui.text(5, 129, "..."..config.NeatConfig.SaveFile:sub(#config.NeatConfig.SaveFile - 55))