Search code examples
netlogopatch

Netlogo How to store transfomed patches


I want to know if there is a quick way to know when a turtle is near a patch with certain characteristics and It changes it.

I have some farmers, patches with agriculture and patches protected areas. protected is a patch-own variable.

The farmer is able to transform every patch.

ask u-pequeños [if any? patches in-radius 20 with [pcolor = yellow and IUA > 5][ask patches in-radius 20 with [pcolor = yellow and IUA > 5] [set pcolor red]

However, I want them to know how many of those transformed patches are protected and store the number. I know the first part is to create a variable like transformed-protected, but how will they know the amount of patches?


Solution

  • I would suggest that you count with the same condition as you used for the ask (pcolor = yellow and IUA > 5), but add another condition which is protected = true. If you do this right before you ask them to change the color, you should get the number of protected patches that are going to be transformed in the next step.

    let transformed-protected 0
    ask u-pequeños [
      if any? patches in-radius 20 with [pcolor = yellow and IUA > 5][
        set transformed-protected count patches in-radius 20 with [pcolor = yellow and IUA > 5 and protected = true]
        ask patches in-radius 20 with [pcolor = yellow and IUA > 5] [set pcolor red]
      ]
    ]