【发布时间】:2017-07-02 15:43:30
【问题描述】:
我正在尝试制作 2048 游戏的 Netlogo 模拟。我已经实现了三个由权重参数确定的启发式函数,并希望使用行为空间来运行模拟并检查赢得这场比赛的最佳策略是什么。
过程搜索使用导出/导入世界原语搜索可能的移动并选择启发式函数具有最高值的移动。
问题是这个过程非常慢(由于每轮调用四次 import-world 函数)。您是否有任何想法如何在不经常导出和导入世界的情况下实现这一点?
这是我的 AI 入门课程的一个项目。几天后到期,我似乎找不到任何解决方案。
代码的相关部分如下。程序 move-(direction) 都可以正常工作,变量 moveable? 如果方块可以沿所述方向移动则为真,否则为假。它在 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
【问题讨论】:
标签: artificial-intelligence netlogo 2048