我不能为自己的品种设置不同的颜色

时间:2018-07-03 21:44:40

标签: colors netlogo

如果我在Netlogo上多次运行此代码,有时会出现一个绿色和两个红色,有时是三个红色,这是错误还是代码有问题?

response = client.newCall(request).execute();

1 个答案:

答案 0 :(得分:1)

您的代码似乎没有什么问题-我只运行了10000次稍微简化的版本,并且没有实例中除了绿色和2红色以外还有其他计数。尝试对您的设置进行以下修改:

breed [greens a-green]
breed [reds a-red]

globals [ green-count red-count ]

to setup 
  create-greens 1 [
    set color green 
    setxy random-xcor random-ycor
  ]
  create-reds 2 [
    set color red 
    setxy random-xcor random-ycor
  ]
end

要运行几次并跟踪每种颜色的计数:

to colors-check
  ca
  set green-count []
  set red-count []
  repeat 10000 [
    ask turtles [ die ]
    setup
    set green-count lput count turtles with [ color = green ] green-count
    set red-count lput count turtles with [ color = red ] red-count
  ]
  print word "Green counts recorded: " remove-duplicates green-count
  print word "Red counts recorded: " remove-duplicates red-count
  reset-ticks
end

对我来说输出是:

Green counts recorded: [1]
Red counts recorded: [2]

这告诉我,对于所有10000次重复,颜色计数均符合预期(否则,删除重复项时会看到其他数字)。设置后,也许还有其他命令在运行?