3

有没有办法在模拟过程中产生海龟,即使它们死了。在我的模拟中,鱼正在吃浮游生物,所以如果它们遇到浮游生物,浮游生物就会死亡/被吃掉。然而,当一条鱼不能再吃浮游生物时,它就会死亡,因为它不再通过食用浮游生物来获取能量。所以当所有的鱼都死了,浮游生物应该会回来;由于迁移等,并迅速增长。我不确定如何实施?create 功能在这里不起作用,仅在设置中起作用。

to plankton-reproduce
  if random-float 100 < reproduce-plankton [
    set energy (energy / 2)
    hatch 1 [setxy random-xcor random-ycor]
  ]
  if count plankton < 10 [
    create-plankton 20
    setxy random-xcor random-ycor
  ]

错误:你不能在海龟上下文中使用 create-plankton,因为 create-plankton 只是观察者

4

2 回答 2

2

我想我可以理解这个问题。

要让海龟创建海龟,请使用 HATCH。如果您使用,您的代码将起作用(如果我理解的话)

hatch-plankton 20

代替

 create-plankton 20

我做对了吗?海龟hatch、补丁spawn和观察者create。孵化的海龟将与孵化的海龟相同,并且都将在hatch被调用的地方聚集在一起。假设你不想要那个。利用

hatch-plankton 20 [setxy random-xcor random-ycor]
于 2015-12-03T16:14:29.910 回答
0

我已经在代码中加入了这个,但是当浮游生物的数量为零时,不会有浮游生物重生,这是因为所有的浮游生物都死了,不能孵化。您是否知道在模拟过程中产生浮游生物或重生海龟的另一种方法,即使它们死了?在重现浮游生物的代码下面:

to plankton-reproduce
  while [count plankton != 0 and count plankton < 3000]
    [ if random-float 100 < reproduce-plankton
      [set energy (energy / 2)
       hatch-plankton 1 [setxy random-xcor random-ycor]]]
  if count plankton = 0
  [set energy 1
  hatch-plankton 20 [setxy random-xcor random-ycor]]
end
于 2015-12-03T20:31:39.840 回答