我设法建立了我的小模型,但我确实收到了错误,但不知道为什么?
Ps:我是一个血腥的初学者
错误代码是:
您无法在海龟环境中使用迁移,因为migarte仅限观察者。
那我该怎么办?
感谢您的回答。
breed [fish a-fish]
breed [boats boat]
boats-own [profit]
to setup
clear-all
ask patches [set pcolor blue]
set-default-shape fish "fish"
create-fish initial-number-fish
[
set color grey
set size 1.0
setxy random-xcor random-ycor
]
set-default-shape boats "boat"
create-boats initial-number-boats
[
set color black
set size 1.5
set profit random (1 * profit-per-fish)
setxy random-xcor random-ycor
]
reset-ticks
end
to go
if not any? turtles [stop]
ask fish
[
move
fish-reproduce
]
ask boats
[
move-boats
catch-fish
death
reproduce-boats
migrate
]
tick
end
to move
rt random 50
lt random 50
fd 1
end
to fish-reproduce
if random-float 100 < fish-growth
[hatch 1 [rt random-float 360 fd 1]]
end
to move-boats
rt random 50
lt random 50
fd 1
set profit profit - 0.1
end
to catch-fish
let prey one-of fish-here
if prey != nobody
[ask prey [die]
set profit profit + profit-per-fish]
end
to death
if profit < 0 [die]
end
to reproduce-boats
if profit > 1
[
set profit (profit / 2)
hatch 1 [rt random-float 360 fd 1]]
end
to migrate
if random-float 100 < random-spawn-rate
[create-turtles 2 [rt random-float 360 fd 1]]
end
答案 0 :(得分:2)
在NetLogo中创建新海龟有3种不同的基元:
create
(观察员),hatch
(海龟)和sprout
(补丁)。
每个人只能在特定的环境中工作。
这意味着您必须了解调用程序的上下文。
在您的示例中,您在create-turtles
(特别是ask turtles
)上下文中调用ask boats
原语。这意味着您处于海龟环境中而不是观察者环境中,因此不允许使用create-turtles
。
要解决您的问题,您只需将create-turtles
替换为hatch
(或hatch-<breed>
,如hatch-fish
,如果您想要在特定品种中生成新代理,请