Added the ablity to loop through several states

There is now a configure option to enable the ability to loop through a list of save states. It changes states each time there is a new generation. This option has been disabled by default.
This commit is contained in:
Colton 2023-09-14 20:00:38 -05:00 committed by GitHub
parent 73ff1a918c
commit c4e4bb31ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 19 deletions

View file

@ -3,15 +3,19 @@ local _M = {}
_M.StateDir = "state/" _M.StateDir = "state/"
_M.PoolDir = "pool/" _M.PoolDir = "pool/"
_M.TestName = "test1"
--[[ --[[
At the moment the first in list will get loaded. If LoopStates in NeatConfig is enabled it will loop through the states in order changing states with each generation.
Rearrange for other savestates. (will be redone soon) States currents have to be manually added to the list below as well as put in the state folder.
--]] --]]
_M.State = { _M.State = {
"DP1.state", -- Donut Plains 1 "DonutPlains1.state",
"YI1.state", -- Yoshi's Island 1 "DonutPlains4.state",
"YI2.state", -- Yoshi's Island 2 "IggyCastle.state",
"YoshiIsland1.state",
"YoshiIsland2.state"
} }
--[[ --[[
@ -25,7 +29,7 @@ _M.State = {
_M.StartPowerup = 0 _M.StartPowerup = 0
_M.NeatConfig = { _M.NeatConfig = {
Filename = _M.PoolDir .. _M.State[1], LoopStates = false,
Population = 300, Population = 300,
DeltaDisjoint = 2.0, DeltaDisjoint = 2.0,
DeltaWeights = 0.4, DeltaWeights = 0.4,

View file

@ -8,6 +8,9 @@ mathFunctions = require "mathFunctions"
Inputs = config.InputSize+1 Inputs = config.InputSize+1
Outputs = #config.ButtonNames Outputs = #config.ButtonNames
stateID = 1
stateCount = #config.State
function newInnovation() function newInnovation()
pool.innovation = pool.innovation + 1 pool.innovation = pool.innovation + 1
return pool.innovation return pool.innovation
@ -624,6 +627,15 @@ function newGeneration()
pool.generation = pool.generation + 1 pool.generation = pool.generation + 1
if config.NeatConfig.LoopStates then
StateID = StateID + 1
if StateID == StateCount then
StateID = 1
end
end
pool.maxFitness = 0
--writeFile("backup." .. pool.generation .. "." .. forms.gettext(saveLoadFile)) --writeFile("backup." .. pool.generation .. "." .. forms.gettext(saveLoadFile))
writeFile(forms.gettext(saveLoadFile) .. ".gen" .. pool.generation .. ".pool") writeFile(forms.gettext(saveLoadFile) .. ".gen" .. pool.generation .. ".pool")
end end
@ -640,7 +652,7 @@ function initializePool()
end end
function initializeRun() function initializeRun()
savestate.load(config.NeatConfig.Filename); savestate.load(config.StateDir .. config.State[stateID]);
if config.StartPowerup ~= NIL then if config.StartPowerup ~= NIL then
game.writePowerup(config.StartPowerup) game.writePowerup(config.StartPowerup)
end end
@ -682,11 +694,6 @@ function evaluateCurrent()
joypad.set(controller) joypad.set(controller)
end end
if pool == nil then
initializePool()
end
function nextGenome() function nextGenome()
pool.currentGenome = pool.currentGenome + 1 pool.currentGenome = pool.currentGenome + 1
if pool.currentGenome > #pool.species[pool.currentSpecies].genomes then if pool.currentGenome > #pool.species[pool.currentSpecies].genomes then
@ -706,12 +713,6 @@ function fitnessAlreadyMeasured()
return genome.fitness ~= 0 return genome.fitness ~= 0
end end
form = forms.newform(500, 500, "Mario-Neat")
netPicture = forms.pictureBox(form, 5, 250,470, 200)
--int forms.pictureBox(int formhandle, [int? x = null], [int? y = null], [int? width = null], [int? height = null])
function displayGenome(genome) function displayGenome(genome)
forms.clear(netPicture,0x80808080) forms.clear(netPicture,0x80808080)
local network = genome.network local network = genome.network
@ -1000,6 +1001,15 @@ function onExit()
forms.destroy(form) forms.destroy(form)
end end
if pool == nil then
initializePool()
end
form = forms.newform(500, 500, "Mario-Neat")
netPicture = forms.pictureBox(form, 5, 250,470, 200)
--int forms.pictureBox(int formhandle, [int? x = null], [int? y = null], [int? width = null], [int? height = null])
writeFile(config.PoolDir.."temp.pool") writeFile(config.PoolDir.."temp.pool")
event.onexit(onExit) event.onexit(onExit)
@ -1025,7 +1035,7 @@ saveButton = forms.button(form, "Save", savePool, 5, 102)
loadButton = forms.button(form, "Load", loadPool, 80, 102) loadButton = forms.button(form, "Load", loadPool, 80, 102)
playTopButton = forms.button(form, "Play Top", playTop, 230, 102) playTopButton = forms.button(form, "Play Top", playTop, 230, 102)
saveLoadFile = forms.textbox(form, config.NeatConfig.Filename .. ".pool", 170, 25, nil, 5, 148) saveLoadFile = forms.textbox(form, config.PoolDir .. config.TestName .. ".pool", 170, 25, nil, 5, 148)
saveLoadLabel = forms.label(form, "Save/Load:", 5, 129) saveLoadLabel = forms.label(form, "Save/Load:", 5, 129)
spritelist.InitSpriteList() spritelist.InitSpriteList()
spritelist.InitExtSpriteList() spritelist.InitExtSpriteList()