【问题标题】:Netlogo Mekka Model - need directionsNetlogo Mekka 模型 - 需要方向
【发布时间】:2014-06-17 06:47:55
【问题描述】:

我正在使用 Netlogo 为我的大学完成这项任务,但我真的被困住了。 我刚开始使用 Netlogo,我正试图与一些朝圣者一起重建 Mekka。

我一直在尝试很多不同的代码,添加新的,尝试一下,删除一些,但这是我到目前为止想出的:

 turtles-own
[direction                ;;  1 follows right-hand wall, -1 follows left-hand wall
 way-is-clear?            ;; reporter - true if no wall ahead
 checked-following-wall?]

globals [halfedge]

breed [agents agent ] 

agents-own [ around visible ]

to setup
  create-agents 500 [
    set color green
    set size 2
    ; distribute agents randomly
    setxy pxcor = halfedge pycor = halfedge 
    set heading random 360
    ; ensure that each is on its own patch
    while [any? other agents-here] [ fd 1 ]

  ]
end

to bounce 
  if [pcolor] of patch-at dx 0 = blue [
    set heading (- heading)
  ]
  if [pcolor] of patch-at 0 dy = blue [
    set heading (180 - heading)
  ]
end

to go 
  ask agents [ count-those-around ]
  ask agents [ move ]
end

; store the number of agents surrounding me within
; local-radius units
; and the agents that I can see within visible-radius

to count-those-around
  set around count agents with [self != myself] in-radius 
  local-radius
  set visible agents with [self != myself] in-radius 
  visible-radius
end

to move 
   ;; turn right if necessary
  if not wall? (90 * direction) and wall? (135 * direction) [ rt 90 * direction ]
  ;; turn left if necessary (sometimes more than once)
  while [wall? 0] [ lt 90 * direction ]
  ;; move forward
  fd 1
end

; face towards the most popular local spot 
to face-towards
  face max-one-of visible [around]
end
; face away from the most popular local spot
to face-away
  set heading towards max-one-of visible [around] - 180
end 

to setup-center
   clear-all
  set halfedge int (edge / 2)
  ask patches[
    if (pxcor = (- halfedge) and pycor >= (- halfedge) and pycor <= (0 + halfedge) )
      [set pcolor blue]                                ;; ... draws left edge in blue
    if ( pxcor = (0 + halfedge) and pycor >= (- halfedge) and pycor <= (0 + halfedge) )
      [set pcolor blue]                                ;; ... draws right edge in blue
    if ( pycor = (- halfedge) and pxcor >= (- halfedge) and pxcor <= (0 + halfedge) )
      [set pcolor blue]                                ;; ... draws bottom edge in blue
    if ( pycor = (0 + halfedge) and pxcor >= (- halfedge) and pxcor <= (0 + halfedge) )
      [set pcolor blue]                                ;; ... draws upper edge in blue
    ]
end
  • 这个想法是,首先,设置一个类似于天房的正方形。
  • 之后,海龟就设置好了。
  • 他们应该都以逆时针方向绕墙走。
  • 应该有一位“领袖”带领所有朝圣者在天房周围。

现在天房已成功绘制,唯一的问题是海龟不应该在那里产卵或碰到它(因此有凹凸代码)。 此外,它们随机四处走动,我不知道如何让它们以 Counter-Clickwise 的形式移动,跟随一个不同颜色的领导者。

有谁能帮帮我吗?我会永远感激不尽!

【问题讨论】:

    标签: netlogo direction agents leader


    【解决方案1】:

    你可能试图通过一次编写一个大程序来一次学习太多东西。

    从编写一个非常小的程序开始;让它工作;尝试对其进行非常小的改进,并使其发挥作用;等等。如果您在任何时候卡住了,请到这里,显示您的代码最多有 one 个问题,并询问 one 关于您特别关注的一个问题的问题'目前卡住了。这是获得帮助的最有效方式。

    一些随机编码技巧:

    这不是有效的代码:

    setxy pxcor = halfedge pycor = halfedge
    

    setxy 需要两个数字,但您传递给它两个布尔值:pxcor = halfedge 是真或假,pycor = halfedge 也是真或假。我想你的意思可能只是setxy halfedge halfedge

    agents with [self != myself] 可以简单地替换为other agents

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 1970-01-01
      • 1970-01-01
      • 2011-08-30
      • 1970-01-01
      相关资源
      最近更新 更多