【发布时间】:2017-07-26 11:46:24
【问题描述】:
我正在尝试运行用 Lua 编写的出色的 Mar I/O 人工智能(更多信息请访问 https://youtu.be/qv6UVOQ0F44)
AI 在 BizHawk 模拟器 (v.2.1.1) 的 Lua (v.5.1) 控制台中成功运行,但在尝试重新加载算法的先前状态时出现错误。
打开文件后,file:read("*number") 似乎总是返回 0,而 read("*all") 和 "*line" 都正确读取了内容。我也试过“*n”但没有运气。
完整脚本地址:https://pastebin.com/ZZmSNaHX
function loadFile(filename)
local file = io.open(filename, "r")
pool = newPool()
pool.generation = file:read("*number")
pool.maxFitness = file:read("*number")
...
function writeFile(filename)
local file = io.open(filename, "w")
file:write(pool.generation .. "\n")
file:write(pool.maxFitness .. "\n")
...
生成的文件开头为:
18[LF]
1938[LF]
...
但是,我仍然在控制台中看到 0:
console.writeline("Gen " .. pool.generation) --> "Gen 0"
console.writeline("Max Fitness " .. pool.maxFitness) --> "Max Fitness 0"
同样令人费解的是,这个脚本已经在不同的论坛上讨论过了,似乎没有人报告同样的问题。
【问题讨论】:
-
顺便说一句,
file:write(pool.generation,"\n")更简单。