如果他们看到对方,我需要让两队经纪人打架。 每支球队都有50%的机会获胜。 如果一种药剂的能量低于最初配置的能量,它会损失50%的能量。 我怎么做?我的代码似乎错了。谢谢。
to move-teamA
ask teamA
[
ifelse any? teamB-on patch-right-and-ahead -90 1 or any? teamB-on patch-
ahead 1
[
fd 1
if energy < advance_energy [set energy (energy / 2)]
let x random 1
if x = 0 [fd 1]
if x = 1 [die]]
end
答案 0 :(得分:1)
看看这种方法 - 我认为它是您尝试做的更简单的版本。我忽略了您的energy
组件,因为我不确定您是如何设置的,但您可以根据需要将其放入。
breed [ teamA one-teamA ]
breed [ teamB one-teamb ]
to setup
ca
create-teamA 10 [
setxy random-xcor random-ycor
set color red
]
create-teamB 10 [
setxy random-xcor random-ycor
set color blue
]
reset-ticks
end
to go
ask turtles [
let enemy one-of turtles in-cone 1 90 with [ breed != [breed] of myself ]
ifelse enemy != nobody [
ifelse random 2 = 1 [ ; if visible enemy exists, flip coin
ask enemy [ die ] ; if 1, enemy dies, I move forward
fd 1
] [
die
] ; if 0, I die
] [
fd 1
] ; if no enemy, move forward
]
tick
end