Treat adjacent similarly colored cells as a path and walk it recursively, trying each direction in turn. Keep a tally as you walk and make any necessary determinations when the call chain is complete.
I'd recommend, however, using an array of Types and not just a simple integer array. This way you can track housekeeping information as you walk the grid.
I'd recommend, however, using an array of Types and not just a simple integer array. This way you can track housekeeping information as you walk the grid.