What algorithm can I use to detect simple shapes in a 4x4 matrix?

Posted by ion on Game Development See other posts from Game Development or by ion
Published on 2012-04-10T23:04:19Z Indexed on 2012/04/10 23:45 UTC
Read the original article Hit count: 380

Filed under:
|
|

I'm working on a simple multiplayer game that receives a random 4x4 matrix from a server and extracts a shape from it.

For example:

XXOO       OXOO
XXOX       XXOO
XOOX  and  XOOO
XXXX       OXXX

So in the first matrix the shape I want to parse is:

  oo
  o
 oo

and the 2nd:

  oo
  oo
 ooo

I know there must be an algorithm for this because I saw this kind of behavior on some puzzle games but I have no idea how to go about to detecting them or even where to start.

So my question is: How do I detect what shape is in the matrix and how do I differentiate between multiple colors? (it doesn't come only in X and O, it comes in a maximum of 4). Additionally, the shape must be a minimum of 4 blocks.

© Game Development or respective owner

Related posts about algorithm

Related posts about objective-c