根据收入水平更改补丁的颜色

Change the color of the patch based on income level

Hi, this is a continuation of my previous question. Basically I'm trying to differentiate the patches by its income level and once I have established this I will set a monitor to count them. However, when I run the model the patches are not updating. Where am I going wrong? Appreciate your assistance.

 turtles-own [wealth]
patches-own [income]



to setup
  ca
  setup-turtles
  setup-patches
  reset-ticks

end

to setup-turtles
  create-turtles num-turtles
  ask turtles
  [
    set shape "person"
    set size 1
    setxy random-xcor random-ycor
    set wealth 100
  ]
end

to setup-patches
  ask n-of 2000 patches [ set pcolor green ] ;; to identify patches that will accumulate income from turtles
end


to go
  if not any? turtles with [wealth > 0] [stop]
  move-turtles
  spend
  tick
end

to move-turtles  ;; turtles to stop once they are spend all their wealth
  ask turtles [
   ifelse wealth > 0 
    [rt random 360 forward 1]
    [stop]

  ]

end

to color-patches  ;; patch colors to change based on their income level
  ask patches [
    ifelse income > 0 and income < 100 [
      set pcolor 15
    ] [
      ifelse income > 100 and income < 200 [
        set pcolor 45
      ] [
        ifelse income > 200 [
          set pcolor 64
        ] [
          set pcolor green
        ]
      ]
    ]
  ]

end

to spend
  ask turtles with [wealth > 0] [
    if pcolor = green [
      set wealth wealth - 1
      set income income + 1
    ]
   ]
end

简短的回答是,您创建了更新补丁颜色的程序,但您从未告诉 NetLogo 运行 它。你可能想在你的 go 过程中添加一行,我认为这个命令:

to go
  if not any? turtles with [wealth > 0] [stop]
  move-turtles
  spend
  color-patches               ; this is what you are missing
  tick
end

这与您的问题无关,但我也注意到您有此移动代码:

to move-turtles  ;; turtles to stop once they are spend all their wealth
  ask turtles [
   ifelse wealth > 0 
    [rt random 360 forward 1]
    [stop]
  ]
end

您不需要询问每只海龟,然后使用 stop 为其中一些退出,相反,使用 with 过滤海龟通常更容易。因此该代码可以替换为:

to move-turtles
  ask turtles with [wealth > 0] [
    rt random 360
    forward 1
  ]
end