NetLogo:While/repeat 海龟运动跟随补丁自有变量
NetLogo: While/repeat turtle movement following patches-own variables
我想让我的乌龟在世界各地漫游,并在其半径范围内查找具有最高 totalattract
值的补丁。 Turtle 应该一直游荡到它的 [energy] > [totalattract]
补丁,然后 turtle 必须留在补丁上 运行 一个过程 [infest]
。我想 运行 在 1 个刻度内执行此操作,所以我想使用 while 或 repeat 或它们的组合,但我无法弄清楚确切的语法。与ifelse条件相同。
我这里的例子 while
条件只是 运行 永远结束不会停止。
另外,我想测量乌龟运动开始的斑块和乌龟必须停留的斑块之间的欧氏(最短)距离。
谢谢!
patches-own [
totalattract
]
turtles-own [
energy
efficiency
]
to setup
clear-all
ask patches [
set totalattract random 4
]
ask n-of 5 patches [set totalattract 4]
ask patches with [totalattract = 4][
set pcolor red
]
ask patches [
set plabel totalattract
]
setup-turtles
reset-ticks
end
to setup-turtles
create-turtles 1 [ setxy random-xcor random-ycor
set color green
set energy 10
set efficiency 5
]
end
to go
ask turtles [if color = green [move-turtles]
if ([totalattract] of patch-here - energy) >= 0 [beetle_infest]
]
tick
end
to move-turtles
set energy (energy - 1)
while [energy < 4]
[
move-to max-one-of patches in-radius 3 [ totalattract ] ]
end
to beetle_infest
ask patch-here [set pcolor pink]
end
问题是它移动到了它应该移动的地方,但并没有导致能量增加,所以while [energy < 4]
条件仍然满足。如下添加 set energy 10
将打破无限循环,但您需要将其更改为您真正希望乌龟执行的任何操作以增加其能量。
to move-turtles
set energy (energy - 1)
while [energy < 4]
[
move-to max-one-of patches in-radius 3 [ totalattract ]
set energy 10 ] ; put stuff here to increase energy
end
我想让我的乌龟在世界各地漫游,并在其半径范围内查找具有最高 totalattract
值的补丁。 Turtle 应该一直游荡到它的 [energy] > [totalattract]
补丁,然后 turtle 必须留在补丁上 运行 一个过程 [infest]
。我想 运行 在 1 个刻度内执行此操作,所以我想使用 while 或 repeat 或它们的组合,但我无法弄清楚确切的语法。与ifelse条件相同。
我这里的例子 while
条件只是 运行 永远结束不会停止。
另外,我想测量乌龟运动开始的斑块和乌龟必须停留的斑块之间的欧氏(最短)距离。
谢谢!
patches-own [
totalattract
]
turtles-own [
energy
efficiency
]
to setup
clear-all
ask patches [
set totalattract random 4
]
ask n-of 5 patches [set totalattract 4]
ask patches with [totalattract = 4][
set pcolor red
]
ask patches [
set plabel totalattract
]
setup-turtles
reset-ticks
end
to setup-turtles
create-turtles 1 [ setxy random-xcor random-ycor
set color green
set energy 10
set efficiency 5
]
end
to go
ask turtles [if color = green [move-turtles]
if ([totalattract] of patch-here - energy) >= 0 [beetle_infest]
]
tick
end
to move-turtles
set energy (energy - 1)
while [energy < 4]
[
move-to max-one-of patches in-radius 3 [ totalattract ] ]
end
to beetle_infest
ask patch-here [set pcolor pink]
end
问题是它移动到了它应该移动的地方,但并没有导致能量增加,所以while [energy < 4]
条件仍然满足。如下添加 set energy 10
将打破无限循环,但您需要将其更改为您真正希望乌龟执行的任何操作以增加其能量。
to move-turtles
set energy (energy - 1)
while [energy < 4]
[
move-to max-one-of patches in-radius 3 [ totalattract ]
set energy 10 ] ; put stuff here to increase energy
end