我正在尝试按照与此视频相同的方式创建模拟 (1:29 - 1:45)
https://www.youtube.com/watch?v=pqBSNAOsMDc
我认为实现无限循环过程的一个简单方法是让海龟面向 0,0,然后在半径 90 内寻找空块(因此它们总是向右看。
我收到错误代码..
'没有定义从点 (3,-6) 到同一点的航向。'
有人可以用我的代码指出正确的方向吗?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
turtles-own [ faction ]
to setup
clear-all
ask patches [ set pcolor white ]
set-patch-size 7
resize-world min-pxcor max-pxcor min-pycor max-pycor
ask patch 0 0
[ ask patches in-radius ( max-pxcor * .6) with [ random-float 100 < density ]
[ sprout 1
[
set shape "circle"
assign-factions
set color faction-color
set size 1 ] ] ]
ask turtles-on patch 0 0 [ die ]
reset-ticks
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to-report faction-color
report red + faction * 30
end
to assign-factions
let angle 360 / factions
foreach n-values factions [?] [
ask patch 0 0 [
sprout 1 [
set heading ? * angle
ask turtles in-cone max-pxcor angle [ set faction ? + 1 ]
die ] ] ]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
ask turtles
[ set heading (towards patch-at 0 0) ; adjusts heading to point to centre
let empty-patches neighbors with [not any? turtles-here]
if any? empty-patches in-radius 90
[ let target one-of empty-patches
face target
move-to target ]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Run Code Online (Sandbox Code Playgroud)
这是因为in-radius
可以返回乌龟本身。要解决此问题,只需更改该行
ask patches in-radius .....
Run Code Online (Sandbox Code Playgroud)
到
ask other patches in-radius .....
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1384 次 |
最近记录: |