Netlogo让海龟在一个区域内随意行走
发布时间:2022-05-22 07:41:22 313
相关标签: # 补丁
假设我有一个海滩和一个海洋,分别用灰色和青色补丁表示。我有一些海龟(鱼),我将它们的起始位置随机限制在海洋的某个地方。现在,鱼的每一个刻度都按照从正态分布(均值 = 0,SD = 1)得出的步长进行随机游走。从逻辑上讲,当移动鱼时,应该留在海洋中而不是移动到海滩上。我尝试了与while []将鱼的起始位置限制在海洋相同的方法,但这似乎在这里不起作用,即鱼根本不动。有什么想法吗?
编辑:除了在水中有 2 条鱼外,我还有 2 只其他海龟(例如牛和羊)在陆地上,与鱼类似,它们在移动时不能/不应该进入水中(实际上我有 3这样的“栖息地”总和,乌龟不应该离开它们开始的栖息地)。当我将 LeirsW 的解决方案用于鱼和牛/羊时,我的 Netlogo 冻结了,我不得不强制退出。对此有什么想法吗?
编辑 2: x0 和 y0 没有错误,需要保留在代码中。
更新代码如下:
breed [ fishes fish ]
fishes-own
[
x0 y0 xcur ycur
]
to setup
clear-all
reset-ticks
ask patches [set pcolor gray]
ask patches with [ pycor < (max-pycor / 2) ] [ set pcolor cyan ]
create-fishes 4
[
setxy random-xcor random-ycor
set x0 xcor
set y0 ycor
ifelse who <= ( 3 * 0.5 ) ; Set proportion of fishes in lagoon determined by slider
[ set shape "fish" set size 2 ]
[ set shape "fish" set size 3 ]
set color white
while [ pcolor != cyan ] [ setxy random-xcor random-ycor ] ; Set fishes coordinates for lagoon habitat only
]
create-fishes 4
[
setxy random-xcor random-ycor
set x0 xcor
set y0 ycor
ifelse who <= ( 4 - 1 + 4 * 0.5 )
[ set shape "sheep" set size 2 set color yellow ]
[ set shape "cow" set size 2 set color yellow]
;set color white
while [ pcolor != gray ] [ setxy random-xcor random-ycor ] ; Set fishes coordinates for bank habitat only
]
end
to go
fish-move
tick
end
to fish-move
ask fishes with [pcolor = cyan]
[
ifelse (random-float 1) < 0.95
[
let destination patch (x0 + random-normal 0 1) (y0 + random-normal 0 1)
while [ [pcolor] of destination != cyan ]
[
set destination patch (x0 + random-normal 0 1) (y0 + random-normal 0 1)
]
move-to destination
set xcur xcor
set ycur ycor
]
[
let destination patch random-xcor random-ycor
while [ [pcolor] of destination != cyan ]
[
set destination patch random-xcor random-ycor
]
move-to destination
set xcur xcor
set ycur ycor
]
]
ask fishes with [pcolor = gray]
[
ifelse (random-float 1) < 0.95
[
let destination patch (x0 + random-normal 0 1) (y0 + random-normal 0 1)
while [ [pcolor] of destination != gray ]
[
set destination patch (x0 + random-normal 0 1) (y0 + random-normal 0 1)
]
move-to destination
set xcur xcor
set ycur ycor
]
[
let destination patch random-xcor random-ycor
while [ [pcolor] of destination != gray ]
[
set destination patch random-xcor random-ycor
]
move-to destination
set xcur xcor
set ycur ycor
]
]
end
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报