如何让其他海龟继承其他龟的事件?在我的代码中,我有这个简单的设置,有50只乌龟。我还有一个恐慌按钮,如果点击它,一些乌龟会将他们的心情设置为恐慌并将颜色变为橙色。
我对这个有一些改变。无视百分比。现在所有海龟都会检查周围的情况,如果他们发现/看到心情=恐慌和颜色橙色的海龟,他们也会惊慌失措并变成橙色。
turtles-own[
mood
]
to setup
__clear-all-and-reset-ticks
create-Humans
end
to create-humans
crt 50[
setxy random-pxcor random-pycor
set color blue
set mood "calm"
]
end
to panic
ask n-of initial-panic turtles [
set mood "panic"
set color orange
]
end
我试过了。
to go
ask turtles[
fd 1
lt random 90]
ask turtles[
ask turtles in-cone 3 60
[ if any? turtles with [ color orange]
set mood "panic"] ]
end
但它不起作用。
答案 0 :(得分:2)
欢迎来到StackOverflow,你可以试试这个:
turtles-own[
mood
]
to setup
__clear-all-and-reset-ticks
create-Humans
panic
end
to create-humans
crt 50[
setxy random-pxcor random-pycor
set color blue
set mood "calm"
]
end
to panic
ask n-of initial-panic turtles [
set mood "panic"
set color orange
]
end
to go
ask turtles[
fd 1
lt random 90
if any? turtles in-cone 3 60 with [ color = orange]
[set mood "panic"
set color orange
]
]
end