This week's giveaway is in the Spring forum.We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!

MR Chen
Ranch Hand
Posts: 32
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

MR Chen
Ranch Hand
Posts: 32
Oops - that title should be "Scoring Code"