有一个白色的斑点,随机移动着10只红海龟和10只蓝海龟。如果蓝色乌龟出现在白色斑块上,我想将一只乌龟的颜色更改为红色。如果另一只蓝色乌龟出现在白色斑块上,我也想将该特定乌龟的颜色也更改为红色。同样。
我为此编写了代码。 (我可以在代码中更改补丁数量,包括蓝色和红色乌龟。首先,只有绿色补丁。当一只红色乌龟进入绿色补丁时,绿色补丁变成白色。我想编写一个代码,使一只蓝龟变成白色斑块,然后蓝龟变成红色)。不幸的是,在我的代码中,如果一只蓝色的乌龟来到了白色的补丁上,那么所有的蓝龟都变成了红色!我想将一只乌龟的颜色改为红色。谢谢!
breed [cows cow] ;Infected mosquitos
breed [sheep a-sheep] ;Susceptible-Mosquitos
to setup
clear-all
set-default-shape cows "bug"
set-default-shape sheep "bug"
reset-ticks
create-cows Infected-Mosquitos-red ; cows=Infected mosquitos
[
set color red
]
create-sheep Susceptible-Mosquitos-blue
; sheep=Susceptible mosquitos
[
set color blue
]
ask turtles [
set size 1
set shape "bug"
setxy random-xcor random-ycor
]
ask turtles[
ifelse coin-flip?
[ifelse coin-flip? [set heading 0][set heading 90]]
[ifelse coin-flip? [set heading 180][set heading 270]]
]
ask n-of humans patches [set pcolor green]
show Infected-Mosquitos-red
show Susceptible-Mosquitos-blue
end
to go
ask turtles
[
ifelse coin-flip?
[ifelse coin-flip? [set heading 0][set heading 90]]
[ifelse coin-flip? [set heading 180][set heading 270]]
forward 1
ask cows[
if pcolor = green
[
set pcolor white
show ticks
]
]
ask sheep[
if pcolor = white
[
ask sheep[
set color red
]
]
]
]
tick
end
to-report coin-flip?
report random 2 = 0
end
我希望只有特定乌龟的颜色才能从白色变为蓝色