Fix some state issues caused by changing scope of requires

This commit is contained in:
Empathic Qubit 2021-03-07 01:00:31 -05:00
parent 281ab7a007
commit cd2ccdb7ee
3 changed files with 12 additions and 10 deletions

View file

@ -17,9 +17,10 @@ _M.PoolDir = _M.ScriptDir .. "/pool/"
_M.State = {
"PiratePanic.lsmv",
"PiratePanicDitch.lsmv",
"PiratePanicKremcoin.lsmv",
}
_M.Filename = _M.PoolDir .. _M.State[2]
_M.Filename = _M.PoolDir .. _M.State[3]
--[[
Start game with specific powerup.

View file

@ -7,6 +7,9 @@ local spritelist = dofile(base.."/spritelist.lua")
local util = dofile(base.."/util.lua")
local _M = {}
spritelist.InitSpriteList()
spritelist.InitExtSpriteList()
KREMCOINS = 0x7e08cc
TILE_SIZE = 32
ENEMY_SIZE = 64
@ -335,10 +338,11 @@ function _M.getInputs()
end
for i = 1,#sprites do
distx = math.abs(sprites[i].x - (partyX+dx*TILE_SIZE))
disty = math.abs(sprites[i].y - (partyY+dy*TILE_SIZE))
local sprite = sprites[i]
distx = math.abs(sprite.x - (partyX+dx*TILE_SIZE))
disty = math.abs(sprite.y - (partyY+dy*TILE_SIZE))
if distx <= TILE_SIZE / 2 and disty <= TILE_SIZE / 2 then
inputs[#inputs] = sprites[i].good
inputs[#inputs] = sprite.good
local dist = math.sqrt((distx * distx) + (disty * disty))
if dist > TILE_SIZE / 2 then

View file

@ -5,7 +5,6 @@ local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*/)(.*)", "%1")
local json = dofile(base.."/dkjson.lua")
local libDeflate = dofile(base.."/LibDeflate.lua")
local config = dofile(base.."/config.lua")
local spritelist = dofile(base.."/spritelist.lua")
local game = dofile(base.."/game.lua")
local mathFunctions = dofile(base.."/mathFunctions.lua")
local util = dofile(base.."/util.lua")
@ -21,8 +20,6 @@ frameAdvanced = {}
saveLoadFile = config.NeatConfig.SaveFile
statusLine = nil
statusColor = 0x0000ff00
spritelist.InitSpriteList()
spritelist.InitExtSpriteList()
Inputs = config.InputSize+1
Outputs = #config.ButtonNames
@ -663,6 +660,7 @@ function on_timer()
pool.currentFrame = 0
timeout = config.NeatConfig.TimeoutConstant
game.clearJoypad()
startKong = game.getKong()
startBananas = game.getBananas()
startKrem = game.getKremCoins()
startCoins = game.getCoins()
@ -852,8 +850,6 @@ function mainLoop (species, genome)
end
end
kong = game.getKong()
local lives = game.getLives()
timeout = timeout - 1
@ -864,6 +860,7 @@ function mainLoop (species, genome)
local bananas = game.getBananas() - startBananas
local coins = game.getCoins() - startCoins
local krem = game.getKremCoins() - startKrem
local kong = game.getKong()
print(string.format("Bananas: %d, coins: %d, Krem: %d, KONG: %d", bananas, coins, krem, kong))
@ -1258,7 +1255,7 @@ function displayForm()
gui.text(130, 30, "Max: " .. math.floor(pool.maxFitness))
--gui.text(330, 5, "Measured: " .. math.floor(measured/total*100) .. "%")
gui.text(5, 65, "Bananas: " .. (game.getBananas() - startBananas))
gui.text(5, 80, "KONG: " .. kong)
gui.text(5, 80, "KONG: " .. (game.getKong() - startKong))
gui.text(5, 95, "Krem: " .. (game.getKremCoins() - startKrem))
gui.text(130, 65, "Coins: " .. (game.getCoins() - startCoins))
gui.text(130, 80, "Lives: " .. game.getLives())