我正在使用 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 的形式移动,跟随一个不同颜色的领导者。
你们中的任何人都可以帮助我吗?我将永远感激不尽!