Help for Counting Connected Yellow Patch Clusters in a Termite Model

Hello everyone,

I am working on a termite model in NetLogo and I am having difficulties correctly counting the connected clusters of yellow patches. What I want to achieve is to detect how many clusters (groups of connected yellow patches) there are in the world and plot that number as the simulation progresses.

So far, my code works, but what it is counting is simply the total number of yellow patches, not the connected clusters. After doing some research, I have tried to use a flood-fill function-based approach to identify the clusters, but I still can’t get it to work as it should.

Here is the code I have developed so far:

Problem:
What I want: To detect how many clusters of connected yellow patches there are and plot that number in real time.
What I get: Instead of counting the clusters, the model is counting the total number of yellow patches.

Question:
Is there any mistake in how I am implementing the flood-fill algorithm to detect clusters? Any suggestions or improvements would be greatly appreciated.

Maybe try this:

1 Like