我正试图让它变成“免疫= 0”和“生病= 0”的海龟在与“生病= 1”的海龟发生碰撞时有机会生病。
ask turtles with [immune = 0 and sick = 0]
[if any? turtles-on patch-ahead 1 with [sick = 1]
[if (random 100) < infection-rate
[set sick 1]
]
]
但是,给出的错误是“WITH期望此输入是一个代理集,但是得到一个数字”。有没有办法做到这一点?
答案 0 :(得分:1)
你正在做的很好,NetLogo只是感到困惑。此代码通过了语法检查程序 - 我在有问题的行中添加了一些括号。
globals [infection-rate]
turtles-own [immune sick]
to testme
ask turtles with [immune = 0 and sick = 0]
[if any? (turtles-on patch-ahead 1) with [sick = 1]
[if (random 100) < infection-rate
[set sick 1]
]
]
end