我試圖做一個2048遊戲的Netlogo模擬。我已經實現了三個由權重參數確定的啓發函數,並希望使用行爲空間來運行模擬,並檢查贏得此遊戲的最佳策略是什麼。NetLogo:2048機器人優化
程序搜索使用導出/導入世界基元搜索可能的移動並選擇啓發函數具有最高值的移動。
問題是這個過程非常緩慢(由於導入世界函數每次被稱爲四次)。如果不經常導出和導入世界,您是否有任何想法來實現這一點?
這是我介紹AI類的項目。這是在幾天後,我似乎無法找到任何解決方案。
代碼的相關部分如下。程序移動 - (方向)所有工作正常和變量可移動?如果方塊可以在所述方向上移動則爲true,否則爲false。它在程序中檢查移動檢查調用移動 - (方向)。
我非常感謝您的幫助。 :)
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