简体   繁体   中英

Finding same adjacent values in 2D array, returning number of values

I am making a game, somewhat similar to connect 4, in that the aim is to connect same values in a grid. However, differently from connect 4, the connected values do not have to be in one straight line. For example:

0000

0100

0111

Where "1" is an item dropped by the player, I need to make an algorithm to tell me how many connections were made (4), and where on the grid. Whether you can point me in the right direction for where to look, give advice or even code, I appreciate all and any help! :) Btw I'm making this program in C#, so any language specific stuff has gotta be for that

THANKS "The Javatar" :) seems to work

This is a classic Fill algorithm. There are two ways you can implement it. Either with a recursive method or using queue (being equivalent to DFS / BFS traversal of a graph).

Here are all the information you would need for implementing it :) https://en.wikipedia.org/wiki/Flood_fill

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM