So, I'm implementing a game as my private get-started-in-Java project (here's a link to a description of the game, if you're interested:
http://www.boardgamegeek.com/game/201) and am trying to write the scoring code, which is becoming insanely complicated, so I think I'm doing it wrong.
In brief:
The board is a 9x9 grid, and I'm storing the pieces in a multidimensional array. At the end of the game, each player scores points for their groups of adjacent* pieces. Each group of pieces is worth N^2 points (where N is the number of pieces in the group, so 3 adjacent pieces = 9 points)
My pseudo code for this right now is:
1) Start at 0,0. Mark this square as "checked".
2) Which player's piece is here? (if no piece, then skip to next square)
3) Check adjacent squares for matching pieces (but make sure to not check "out of bounds" squares, as this will produce errors)
4) If an adjacent square has a matching piece, then (a)increment the matching piece count, and (b)add this square to a "matching adjacent square that still needs to be checked" list
5) Complete steps 3-4 for all squares adjacent to original checked square
6) Look at the "matching adjacent square that still needs to be checked" list - if nothing is there, then figure the score (based on the "matching pieces count"); but if there are squares in this list, then pick the first one and repeat steps 3-6 until this list is empty (which means you can figure the score)
Does anyone know of a better way to do this???
Many Thanks,
Mike