我正在尝试对 2048 游戏进行 Netlogo 模拟。我已经实现了三个由权重参数确定的启发式函数,并希望使用行为空间来运行模拟并检查赢得这场比赛的最佳策略是什么。
过程搜索使用导出/导入世界原语来搜索可能的移动并选择启发式函数具有最高值的移动。
问题是这个过程非常慢(由于每轮调用四次 import-world 函数)。你有什么想法如何在不经常导出和导入世界的情况下实现这一点吗?
这是我的 AI 入门课程的一个项目。几天后到期,我似乎找不到任何解决方案。
代码的相关部分如下。程序move-(direction)都正常工作且变量可移动?如果正方形可以沿所述方向移动,则为真,否则为假。它在move-(direction)调用的过程moveable-check中进行检查。
非常感谢您的帮助。:)
to search
let x 0
let direction "down"
export-world "state.csv"
move-up
ifelse not any? squares with [moveable?]
[set h-value -5000]
[set x h-value
set direction "up"
import-world "state.csv"]
export-world "state.csv"
move-down
ifelse not any? squares with [moveable?]
[set h-value -5000]
[if h-value > x
[set x h-value
set direction "down"]
import-world "state.csv"]
export-world "state.csv"
move-left
ifelse not any? squares with [moveable?]
[set h-value -5000]
[if h-value > x
[set x h-value
set direction "left"]
import-world "state.csv"]
export-world "state.csv"
move-right
ifelse not any? squares with [moveable?]
[set h-value -5000]
[if h-value > x
[set x h-value
set direction "right"]
import-world "state.csv"]
ifelse direction = "up"
[move-up
print "up"]
[ifelse direction = "down"
[move-down
print "down"]
[ifelse direction = "right"
[move-right
print "right"]
[move-left
print "left"]]]
if not any? squares with [moveable?]
[
ask squares [set heading heading + 90]
moveable-check
if not any? squares with [moveable?]
[ask squares [set heading heading + 90]
moveable-check
if not any? squares with [moveable?]
[ask squares [set heading heading + 90]
moveable-check
if not any? squares with [moveable?]
[stop]]]
]
end