Add option to auto load and save the pool file

This commit is contained in:
Empathic Qubit 2021-05-12 22:23:04 -04:00
parent 0646e57826
commit f4229bfc48
3 changed files with 19 additions and 5 deletions

View file

@ -44,8 +44,9 @@ _M.NeatConfig = {
DisableSound = true,
Threads = 7,
ShowInterface = false,
AutoSave = true,
--Filename = "DP1.state",
SaveFile = _M.Filename .. ".pool",
SaveFile = _M.PoolDir .. "bigbrain.pool",
Filename = _M.Filename,
Population = 300,

View file

@ -411,6 +411,9 @@ local function bytes(x)
return string.char(b1,b2,b3,b4)
end
--- Saves the pool to a gzipped Serpent file
---@param filename string Filename to write
---@return Promise Promise A promise that resolves when the file is saved.
local function writeFile(filename)
return util.promiseWrap(function ()
local file = io.open(filename, "w")
@ -659,7 +662,11 @@ local function newGeneration()
pool.generation = pool.generation + 1
writeFile(_M.saveLoadFile .. ".gen" .. pool.generation .. ".pool")
return writeFile(_M.saveLoadFile .. ".gen" .. pool.generation .. ".pool"):next(function()
if config.NeatConfig.AutoSave then
return writeFile(_M.saveLoadFile)
end
end)
end
local function reset()
@ -686,7 +693,7 @@ end)
local playTop = nil
local topRequested = false
local loadRequested = false
local loadRequested = config.NeatConfig.AutoSave
local saveRequested = false
local resetRequested = false
local function mainLoop(currentSpecies, topGenome)

View file

@ -1,3 +1,4 @@
local mem = require "mem"
local gui, input, movie, settings, exec, callback, set_timer_timeout = gui, input, movie, settings, exec, callback, set_timer_timeout
local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*[/\\])(.*)", "%1")
@ -541,14 +542,19 @@ local function mainLoop(_M, genome)
preferredExit = preferredExit,
waypoints = game.getWaypoints(preferredExit.x, preferredExit.y),
}
-- XXX Insert means add a new one, not overwrite?
table.insert(areaInfo.waypoints, 1, preferredExit)
for i=1,#areaInfo.waypoints,1 do
for i=#areaInfo.waypoints,1,-1 do
local waypoint = areaInfo.waypoints[i]
if waypoint.y > game.partyY + mem.size.tile * 7 then
message(_M, string.format('Skipped waypoint %d,%d', waypoint.x, waypoint.y), 0x00ffff00)
table.remove(areaInfo.waypoints, i)
goto continue
end
local startDistance = math.floor(math.sqrt((waypoint.y - game.partyY) ^ 2 + (waypoint.x - game.partyX) ^ 2))
waypoint.startDistance = startDistance
waypoint.shortest = startDistance
::continue::
end
_M.areaInfo[_M.currentArea] = areaInfo