我想创建一个场景,其中特定事件发生的概率每次发生都会增加。我想为此定义一个局部变量,但出现错误:
"Expected literal value" appeared (\*\*\*)
现在我不知道如何继续。
代码:
; If bird and cat share a patch, the cat should catch (kill) the bird with a certain probability (hunting-skill)
; This probablity shoud increase everytime the cat successfully catches a bird
to catch-event
ask cats [
let hunting-improvment [ hunting-skill * catch-rate-increase ]
if any? birds-here [
if random-float 1 <= hunting-skill [
ask one-of birds-here [
die
set hunting-skill hunting-skill + hunting-improvment
]
]
]
]
end
您似乎错误地使用了
let
和方括号。要么根本不使用括号,要么如果您想使用括号,请使用圆形括号。
这是代码的固定最小示例:
breed [cats cat]
breed [birds bird]
cats-own [hunting-skill catch-rate-increase]
to go
create-cats 5 [
set hunting-skill 0
set catch-rate-increase 1
]
end
to catch-event
ask cats [
let hunting-improvment (hunting-skill * catch-rate-increase)
if any? birds-here [
if random-float 1 <= hunting-skill [
ask one-of birds-here [
die
set hunting-skill hunting-skill + hunting-improvment
]
]
]
]
end