当乌龟到达我命令它去的特定补丁时,它似乎没有改变航向

Turtle doesn't seem to change heading when it reaches the specific patch I ordered it to go to

我试图让乌龟在到达特定 patch/node 坐标时面对另一只乌龟,或者在本例中是一个节点。然而,一旦到达它,海龟似乎并没有阅读下一个 face 命令。我是 netlogo 的新手,所以非常感谢您的帮助。

ask trucks
  [
    face node2 317 
    fd 1
    if ((pxcor = -133 ) and (pycor = 47)) ;; Coordinate of the node2 317
    [
      face node 333
      fd 1
    ]
  ]

没有看到更多与节点等相关的代码,这很难说,但我猜 trucks 实际上正在阅读代码以面对 node 333 并继续前进。然而,下次程序运行时,truck 将再次 face node2 317 并卡住来回移动。

为了演示,请检查您的代码的这个修改版本。

to setup
  ca
  crt 1 [ pd ]
  reset-ticks  
end

to go
  ask turtles [
    print "I'm facing 10 10 and moving forward 1"
    facexy  10 10
    fd 1
    display
    wait 0.15
    if pxcor = 10 and pycor = 10 [
      print "I'm facing 0 10 and moving forward 1"
      facexy 0 10
      fd 1
      display
      wait 0.15
    ]
  ]
  tick
end

如果你想让你的卡车按顺序移动到目标节点,你可能需要一个 trucks-own 变量来存储他们想要去的当前节点,并且可以更新到下一个节点一次他们到了那里。查看模型库中的 "Link-Walking Turtles Example" 以获取相关示例。

编辑

我认为这个例子会有所帮助-使用这个setup,我们定义了三个变量:

  • targets-list- 要访问的补丁列表
  • next-target-当前要访问的补丁
  • counter - 索引 targets-list

**

turtles-own [ counter targets-list next-target ]

to setup
  ca
  crt 1 [
    pd
    set targets-list ( list patch 5 5 patch 5 -5 patch -5 -5 )
  ]
  reset-ticks
end

然后,您可以让海龟根据它们 counter 的当前值使用 counter 到 select 它们的 next-target。当他们到达目标时,他们将他们的 counter 增加 1,以便下一个滴答他们将索引 targets-list 中的下一个条目(使用 item)。更多详情见评论:

to go
  ask turtles [
    ; set my next-target to be the list item indexed by
    ; my counter variable
    set next-target item counter targets-list

    ; face the next-target, and move forward 1 if distance is
    ; greater than 1. If it's less than 1, move-to the target
    ; and increment the counter
    face next-target 
    ifelse distance next-target > 1 [
      fd 1 
    ] [
      move-to next-target 
      set counter counter + 1
    ]

    ; if counter variable is greater than the number of items
    ; in targets-list, reset to 0 as you cannot index an item
    ; that does not exist
    if counter > length targets-list - 1 [
      set counter 0
    ]
  ]

  tick
end

希望这能让您指明正确的方向!