我举了很多例子来检查一只乌龟是否在另一只乌龟面前移动,但我有不同的情况。
在我的工作中,当我的海龟移动时(带有各自的前向值,如fd 0.1 +随机0.9),我发现在一个补丁中有不止一只乌龟。现在,我想
我遵循汽车运动的代码示例(以及其他示例),其中补丁中有一只乌龟的情况,因此使用"补丁提前"原始工作正常,但在我的情况下,在检查提前补丁龟我想先在补丁内检查。
为了更清楚,我附上了我工作快照的一小部分。
这些乌龟的移动方向设定为固定,具有相似标题的乌龟在其指定路径中移动。不同标题的海龟不会进入其他移动海龟的路径。我尝试过的代码如下:
to control-speed
let other-people-here min-one-of other people-here [ distance myself]
;with the above code each turtle find the other turtle but not the turtle ahead
so tried the x-position value for heading 270 and 90 and
y-position value for heading 0 and 180
ifelse other-people-here = nobody [speed-up-people]
[
if heading = 270
[ ifelse precision [xcor] of self 3 < precision [xcor] of other-people-here 3
[let people-ahead-x other-people-here slow-down-people people-ahead-x ]
[let people-ahead-x self slow-down-people people-ahead-x]
]
; if heading = 90 [do same]
; if heading = 0 [do same and check for ycor]
; if heading = 180 [do same and check for ycor]
]
if move-fd < move-fd-min [set move-fd move-fd-min]
if move-fd > move-fd-limit [set move-fd move-fd-limit ]
end
to speed-up-people
set move-fd (move-fd + (speed-up)) ;show move-fd
end
to slow-down-people [people-ahead-x]
set move-fd [move-fd] of people-ahead-x ;show move-fd
set move-fd move-fd - slow-down ;show move-fd
end
这不起作用。我无法理解为什么&#34; move-fd&#34;一旦达到0不会再次增加,最终乌龟在缓慢的程序调用情况下停止移动。
答案 0 :(得分:0)
这是我最终按照先生@Nicolas Payette的指示解决问题的代码。
to control-speed
if (pxcor > -69 and pxcor < 10) and (pycor > -21 and pycor < 142) [
let people-per-patch count people-here
if people-per-patch = 1 [speed-up-people]
if people-per-patch > 1 [
let people-ahead-x other people in-cone (1 + move-fd) 180
let person-ahead-x min-one-of people-ahead-x [distance myself]
if person-ahead-x != nobody [
set move-fd [move-fd] of person-ahead-x
slow-down-people
]
]
]
if move-fd < 0 [set move-fd slow-down]
if move-fd > move-fd-limit [set move-fd move-fd-limit ]
end
to speed-up-people
set move-fd (move-fd + (speed-up))
end
to slow-down-people
set move-fd move-fd - slow-down
end