【问题标题】:How to control a turtle through global variables on Netlogo如何通过 Netlogo 上的全局变量控制乌龟
【发布时间】:2014-01-12 22:05:05
【问题描述】:

我在 Netlogo 上进行一个创建迷宫的项目,我想对其进行编码,以便如果移动的海龟在另一个位置撞到不动的海龟(代表类似障碍物),那么它会打开一个我将创建的“迷你游戏”。但是,当我包含更多海龟并在按钮中使用 ask turtle 0 以使其他海龟不会移动并保持障碍物时,一切都开始滞后。我将如何使用全局变量来解决问题?

【问题讨论】:

  • 如果你能包含与这个问题相关的代码可能会更有帮助
  • 第一个建议是使用补丁而不是使用海龟作为障碍物,因为它们不会移动!
  • 这是个好主意,但我正在考虑为乌龟使用不同的形状...
  • 我认为你需要改写你的问题,你不需要全局变量,你需要一个海龟变量,并且对于有两种类型的海龟,你可以有一个海龟变量 is-moving?然后将其分配为 false 不移动海龟,只要求移动代理去!你也可以使用品种类型

标签: netlogo


【解决方案1】:

这是使用两个品种的同一模型:

breed [Walls wall]
patches-own [is-wall]
breed [Humans person]
Humans-own [target]

to setup
  clear-all
  set-default-shape Walls "tile brick"
  set-default-shape Humans "person"
  set-patch-size 25


  create-humans 1 [
    set heading 90 
    set color white 
    move-to patch -5 -5 
    set target one-of patches with [not any? walls-here]
    ask target [set pcolor green]]
  set-walls
  reset-ticks
end

to set-walls
  ask n-of 10 patches with [not any? humans-here] 
  [
    set pcolor red
    sprout-walls 1 
    [ 
      set color brown
    ] 
  ]
end

to go
  ask humans [ 

    ifelse pcolor != green 
      [
        ifelse [pcolor] of patch-ahead 1 != red
        [
          Your-Move-Function
        ]
        [
          Your-Bounce-Function 
        ]

        leave-a-trail  
      ]
      [
        stop

      ]


  ]


  tick
end


to Your-Move-Function
  let t target 
  face min-one-of all-possible-moves [distance t]
  fd 1
end

to Your-Bounce-Function 
  let t target 
  face min-one-of all-possible-moves [distance t]
end

to-report all-possible-moves
  report patches in-radius 1 with [not any? walls-here and distance myself  <= 1 and distance myself  > 0 and plabel = "" ]
end

to leave-a-trail
  ask patch-here [set plabel ticks]
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多