我想要我的乌龟
1)如果乌龟是红色并遇到红色斑块,则停止十次蜱虫 2)十次蜱虫后,我希望乌龟能继续使用我已经拥有的寻找食物的子程序。
答案 0 :(得分:1)
实现这一目标的一种简单方法是使用某种计数器。这是一个完整的例子:
turtles-own [ counter ]
to setup
clear-all
create-turtles 100 [
set counter 0
setxy random-xcor random-ycor
]
ask n-of 25 turtles [ set color red ]
ask n-of 100 patches [ set pcolor red ]
reset-ticks
end
to go
ask turtles [
ifelse counter = 0 [
look-for-food
if color = red and pcolor = red [
set counter 10
]
] [
set counter counter - 1
set label counter ; just to show what's going on
]
]
tick
end
to look-for-food
; your own look-for-food procedure is presumably different
right random 20
left random 20
forward 1
end