Original Post
this is main part of a super puzzle fighter like game. i have a function which may create a map contains many cells (say 20x20 for instance which means there're 400 cells in total), in each cell there may be an element with a value from 1-8 by shuffle, or 0 means an empty cell. and next step is to check the whole map and try to find if there're any cells with same color could be rectangles. here's a picture to demonstrate that: http://img6.imageshack.us/img6/5378/spf25nq.jpg for example we have a map like this: 0000 0110 0110 or this: 0000 0111 0111 if so, all 4(6) cells with a value 1 could be combined into one special cell as follows: (9 means one cell of a rectangle) 0000 0990 0990 or 0000 0999 0999 it looks very simple, but pls check a map like this: 01100 11110 11110 as u can c there're several cross gems which could be a rectangle gem which some of its neighbors, and also could be another rectangle with other nieghbors. and here's my problem, how could we decide which rectangle is bigger ? if so finally the map should be looked like: 01100 99990 99990 not 09900 19910 19910 because first form is bigger. any idea ?