0

私は 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
  • アイデアは、最初に、カーバ神殿に似た正方形が設定されるということです。
  • その後、カメがセットアップされます。
  • 彼らは皆、反時計回りに壁の周りを歩くことになっています。
  • カーバ神殿周辺のすべての巡礼者を導く 1 人の「リーダー」がいるはずです。

現在、カーバ神殿は正常に描画されていますが、唯一の問題は、カメがそこにスポーンしたり、そこに遭遇したりしないことです (したがって、バンプ コード)。また、それらはランダムに回っていて、色の異なる 1 つのリーダーに続いて、カウンター クリック フォーメーションで移動させる方法がわかりません。

どなたか助けていただけませんか?私は永遠に感謝します!

4

1 に答える 1

2

一度に大きなプログラムを書くことで、一度に多くのことを学ぼうとしているのかもしれません。

非常に小さなプログラムを作成することから始めます。それを機能させます。それに非常に小さな改善を試み、それを機能させます。等々。行き詰まった場合はいつでもここに来て、あなたのコードが壊れている箇所が最大でも1 つであることを示し、現在行き詰まっている特に 1 つの問題について1 つの質問をしてください。それが助けを得る最も効果的な方法です。

いくつかのランダムなコーディングのヒント:

これは有効なコードではありません:

setxy pxcor = halfedge pycor = halfedge

setxyは 2 つの数値を想定していますが、2 つのブール値を渡しています: pxcor = halfedgeis true または false、またpycor = halfedgetrue または false です。という意味かもしれませんsetxy halfedge halfedge

agents with [self != myself]に簡単に置き換えることができますother agents

于 2014-04-30T22:44:13.467 に答える