diff --git a/config.lua b/config.lua index b81d361..c64a490 100644 --- a/config.lua +++ b/config.lua @@ -14,9 +14,10 @@ _M.PoolDir = _M.ScriptDir .. "/pool/" --]] _M.State = { "PiratePanic.lsmv", + "PiratePanicDitch.lsmv", } -_M.Filename = _M.PoolDir .. _M.State[1] +_M.Filename = _M.PoolDir .. _M.State[2] --[[ Start game with specific powerup. diff --git a/game.lua b/game.lua index 21cef2d..0e4d8f8 100644 --- a/game.lua +++ b/game.lua @@ -15,6 +15,7 @@ TILEDATA_POINTER = 0x7e0098 HAVE_BOTH = 0x7e08c2 CAMERA_X = 0x7e17ba CAMERA_Y = 0x7e17c0 +LEAD_CHAR = 0x7e08a4 PARTY_X = 0x7e0a2a PARTY_Y = 0x7e0a2c SOLID_LESS_THAN = 0x7e00a0 @@ -62,7 +63,8 @@ end function _M.getBoth() -- FIXME consider invincibility barrels - return bit.band(memory.readword(HAVE_BOTH), 0x40) + local both = memory.readword(HAVE_BOTH) + return bit.band(both, 0x4000) end function _M.writePowerup(powerup) @@ -180,28 +182,47 @@ function _M.getTile(dx, dy) return 1 end +function _M.getJumpHeight() + local leader = memory.readword(LEAD_CHAR) + local sprite = _M.getSprite(leader) + return sprite.jumpHeight +end + +function _M.getSprite(idx) + local base_addr = idx * 94 + SPRITE_BASE + + local control = memory.readword(base_addr) + + if control == 0 then + return nil + end + + local x = memory.readword(base_addr + 0x06) + local y = memory.readword(base_addr + 0x0a) + local sprite = { + control = control, + screenX = x - 256 - cameraX - 256, + screenY = y - 256 - cameraY - 256, + jumpHeight = memory.readword(base_addr + 0x0e), + x = x, + y = y, + good = spritelist.Sprites[control] + } + + if sprite.good == nil then + sprite.good = -1 + end + + return sprite +end + function _M.getSprites() local sprites = {} for idx = 2,22,1 do - local base_addr = idx * 94 + SPRITE_BASE - - local control = memory.readword(base_addr) - if control == 0 then + local sprite = _M.getSprite(idx) + if sprite == nil then goto continue end - local x = memory.readword(base_addr + 0x06) - local y = memory.readword(base_addr + 0x0a) - local sprite = { - screenX = x - 256 - cameraX - 256, - screenY = y - 256 - cameraY - 256, - x = x, - y = y, - good = spritelist.Sprites[control] - } - - if sprite.good == nil then - sprite.good = -1 - end sprites[#sprites+1] = sprite ::continue:: @@ -272,8 +293,14 @@ function _M.getInputs() inputDeltaDistance[#inputDeltaDistance+1] = 1 tile = _M.getTile(dx, dy) - if tile == 1 --[[and partyY+dy < 0x1B0]] then - inputs[#inputs] = 1 + if tile == 1 then + if _M.getTile(dx, dy-1) == 1 then + inputs[#inputs] = -1 + else + inputs[#inputs] = 1 + end + elseif tile == 0 and _M.getTile(dx + 1, dy) == 1 and _M.getTile(dx + 1, dy - 1) == 1 then + inputs[#inputs] = -1 end for i = 1,#sprites do diff --git a/neat-donk.lua b/neat-donk.lua index c344b51..c19ffa2 100644 --- a/neat-donk.lua +++ b/neat-donk.lua @@ -9,6 +9,7 @@ mathFunctions = dofile(base.."/mathFunctions.lua") util = dofile(base.."/util.lua") kong = 0 +lastBoth = 0 form = nil netPicture = nil runInitialized = {} @@ -734,9 +735,7 @@ end function mainLoop (species, genome) advanceFrame(function() if not config.Running then - advanceFrame(function() - mainLoop(species, genome) - end) + mainLoop(species, genome) return end @@ -793,7 +792,7 @@ function mainLoop (species, genome) -- FIXME Measure distance to target / area exit -- We might not always be horizontal - local hitTimer = game.getHitTimer(powerUpBefore) + local hitTimer = game.getHitTimer(lastBoth) if hitTimer > 0 then partyHitCounter = partyHitCounter + 1 @@ -801,6 +800,7 @@ function mainLoop (species, genome) end powerUp = game.getBoth() + lastBoth = powerUp if powerUp > 0 then if powerUp ~= powerUpBefore then powerUpCounter = powerUpCounter+1 @@ -838,7 +838,7 @@ function mainLoop (species, genome) end - local fitness = bananaCoinsFitness - hitPenalty + powerUpBonus + most + local fitness = bananaCoinsFitness - hitPenalty + powerUpBonus + most + game.getJumpHeight() if startLives < lives then local ExtraLiveBonus = (lives - startLives)*1000 @@ -873,11 +873,8 @@ function mainLoop (species, genome) return end - advanceFrame(function() - mainLoop(species, genome) - end) + mainLoop(species, genome) end) - end function writeFile(filename) diff --git a/pool/PiratePanicDitch.lsmv b/pool/PiratePanicDitch.lsmv new file mode 100644 index 0000000..5196d04 Binary files /dev/null and b/pool/PiratePanicDitch.lsmv differ