Give credit. Factor velocity into timeout calculations
This commit is contained in:
parent
18ceac5dcf
commit
fd182c2a50
3 changed files with 34 additions and 3 deletions
|
@ -24,3 +24,7 @@ An AI based on SethBling's MarI/O to play Donkey Kong Country 2 with lsnes.
|
|||
|
||||
## Notes
|
||||
Only tested on Pirate Panic
|
||||
|
||||
## Credits
|
||||
|
||||
A lot of basic info came from [Donkey Hacks](http://donkeyhacks.zouri.jp/html/En-Us/dkc2/index.html), the NEAT A/I comes from [SethBling's Mar I/O](https://github.com/mam91/neat-genetic-mario), and basic information about the tilemap came from [p4plus2/DKC2-disassembly](https://github.com/p4plus2/DKC2-disassembly)
|
||||
|
|
14
game.lua
14
game.lua
|
@ -24,6 +24,7 @@ MATH_LIVES = 0x7e08be
|
|||
DISPLAY_LIVES = 0x7e0c0
|
||||
|
||||
function _M.getPositions()
|
||||
leader = memory.readword(LEAD_CHAR)
|
||||
tilePtr = memory.readhword(TILEDATA_POINTER)
|
||||
vertical = memory.readword(TILE_COLLISION_MATH_POINTER) == VERTICAL_POINTER
|
||||
partyX = memory.readword(PARTY_X)
|
||||
|
@ -67,6 +68,16 @@ function _M.getBoth()
|
|||
return bit.band(both, 0x4000)
|
||||
end
|
||||
|
||||
function _M.getVelocityY()
|
||||
local sprite = _M.getSprite(leader)
|
||||
return sprite.velocityY
|
||||
end
|
||||
|
||||
function _M.getVelocityX()
|
||||
local sprite = _M.getSprite(leader)
|
||||
return sprite.velocityX
|
||||
end
|
||||
|
||||
function _M.writePowerup(powerup)
|
||||
return
|
||||
-- memory.writebyte(0x0019, powerup)
|
||||
|
@ -183,7 +194,6 @@ function _M.getTile(dx, dy)
|
|||
end
|
||||
|
||||
function _M.getJumpHeight()
|
||||
local leader = memory.readword(LEAD_CHAR)
|
||||
local sprite = _M.getSprite(leader)
|
||||
return sprite.jumpHeight
|
||||
end
|
||||
|
@ -204,6 +214,8 @@ function _M.getSprite(idx)
|
|||
screenX = x - 256 - cameraX - 256,
|
||||
screenY = y - 256 - cameraY - 256,
|
||||
jumpHeight = memory.readword(base_addr + 0x0e),
|
||||
velocityX = memory.readsword(base_addr + 0x20),
|
||||
velocityY = memory.readsword(base_addr + 0x24),
|
||||
x = x,
|
||||
y = y,
|
||||
good = spritelist.Sprites[control]
|
||||
|
|
|
@ -778,15 +778,30 @@ function mainLoop (species, genome)
|
|||
end
|
||||
|
||||
game.getPositions()
|
||||
local timeoutConst = 0
|
||||
if vertical then
|
||||
timeoutConst = config.NeatConfig.TimeoutConstant * 10
|
||||
else
|
||||
timeoutConst = config.NeatConfig.TimeoutConstant
|
||||
end
|
||||
|
||||
-- Don't punish being launched by barrels
|
||||
-- FIXME Will this skew mine cart levels?
|
||||
if math.abs(game.getVelocityY()) > 0x1800 or math.abs(game.getVelocityX()) > 0x1800 then
|
||||
statusLine = "Barrel launch!!!"
|
||||
statusColor = 0x0000ff00
|
||||
timeout = timeoutConst
|
||||
end
|
||||
|
||||
if not vertical then
|
||||
if partyX > rightmost then
|
||||
rightmost = partyX
|
||||
timeout = config.NeatConfig.TimeoutConstant
|
||||
timeout = timeoutConst
|
||||
end
|
||||
else
|
||||
if partyY > upmost then
|
||||
upmost = partyY
|
||||
timeout = config.NeatConfig.TimeoutConstant * 10
|
||||
timeout = timeoutConst
|
||||
end
|
||||
end
|
||||
-- FIXME Measure distance to target / area exit
|
||||
|
|
Loading…
Add table
Reference in a new issue