【问题标题】:NetLogo: 2048 bot optimisationNetLogo:2048 机器人优化
【发布时间】: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


    【解决方案1】:

    您需要能够保存和恢复的最重要和最困难的信息是方块。如果没有import-worldexport-world,这很容易做到(注意以下使用NetLogo 6 语法;如果您仍在使用NetLogo 5,则需要使用foreach 中的旧任务语法):

    to-report serialize-state
      report [(list xcor ycor value)] of squares
    end
    
    to restore-state [ state ]
      clear-squares
      foreach state [ [sq] ->
        create-squares 1 [
          setxy (item 0 sq) (item 1 sq)
          set heading 0 ;; or whatever
          set value item 2 sq
        ]
      ]
    end
    

    value 上面只是显示了如何存储正方形的任意变量。我不确定您与他们关联或需要恢复哪些数据。这段代码背后的想法是,您将有关方格的信息存储在列表列表中,其中每个内部列表都包含一个方格的数据。那么你使用它的方式是:

    let state serialize-state
    ;; make changes to state that you want to investigate
    restore-state state
    

    您可能还需要存储一些全局变量等。这些可以存储在局部变量或state 列表中(更通用,但更难实现)。

    其他一些想法:

    • 现在看起来你只看前方的一个州,并且只有一个可能的位置来放置新的方格(确保你没有作弊,因为你知道新方格的确切位置是)。最终,您可能希望使用一种树搜索来任意向前看。这棵树变得非常大非常快。如果这样做,您将需要使用修剪策略,例如:https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning。此外,这使状态恢复变得更加困难,但仍然可行。您将存储一堆状态而不是单个状态。
    • 您可以使用right 90rt 90 而不是set heading heading + 90

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 2018-05-09
      • 2010-09-25
      • 1970-01-01
      • 2019-01-25
      相关资源
      最近更新 更多