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

View file

@ -8,6 +8,9 @@ mathFunctions = require "mathFunctions"
Inputs = config.InputSize+1
Outputs = #config.ButtonNames
stateID = 1
stateCount = #config.State
function newInnovation()
pool.innovation = pool.innovation + 1
return pool.innovation
@ -624,6 +627,15 @@ function newGeneration()
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(forms.gettext(saveLoadFile) .. ".gen" .. pool.generation .. ".pool")
end
@ -640,7 +652,7 @@ function initializePool()
end
function initializeRun()
savestate.load(config.NeatConfig.Filename);
savestate.load(config.StateDir .. config.State[stateID]);
if config.StartPowerup ~= NIL then
game.writePowerup(config.StartPowerup)
end
@ -682,11 +694,6 @@ function evaluateCurrent()
joypad.set(controller)
end
if pool == nil then
initializePool()
end
function nextGenome()
pool.currentGenome = pool.currentGenome + 1
if pool.currentGenome > #pool.species[pool.currentSpecies].genomes then
@ -706,12 +713,6 @@ function fitnessAlreadyMeasured()
return genome.fitness ~= 0
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)
forms.clear(netPicture,0x80808080)
local network = genome.network
@ -1000,6 +1001,15 @@ function onExit()
forms.destroy(form)
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")
event.onexit(onExit)
@ -1025,7 +1035,7 @@ saveButton = forms.button(form, "Save", savePool, 5, 102)
loadButton = forms.button(form, "Load", loadPool, 80, 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)
spritelist.InitSpriteList()
spritelist.InitExtSpriteList()