Question

I seek to randomly remove, for example, 20%, 50%, 80%, ... of block sides in a grid. My idea is :

  • to assign a label to each road section by using "Patch Clusters Example"

  • then to use the solution from How to randomly remove block side in a grid? as follows :

    to remove-random-roads
    let deleted-road-percent 25 
    let road-section-number length remove 0 remove-duplicates ([cluster] of patches)
    let repetition-number (deleted-road-percent * road-section-number) / 100
    
    repeat repetition-number [
    let random-patch one-of patches with [pcolor = white]
    let side grow-cluster no-patches random-patch
    ask side [ set pcolor brown] ]
    end
    

Unfortunately, the code doesn't work because it removes all roads instead of removing 25% of roads in the landscape. I don't understand why it does that ?

Thanks in advance for your help.

Was it helpful?

Solution

There are two possible explanations:

  1. Your computation of how many roads to remove is wrong.
  2. Your code for removing the roads is wrong.

So the next step you need to take is figure out which of the two it is.

After let repetition-number ..., add:

print repetition-number

Is the value printed correct? If no, pursue path #1. If yes, pursue path #2. (And if still stuck, come back here and tell us which path you need help with.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top