views:

55

answers:

1

I'm working on a game as an assignment for school in java. The game currently is designed for Console.

The game is for 2 players, one attacking from North to South, and the other from West to East. The purpose of the game is to build a "bridge"/"path" between the 2 of your sides before your opponent does.

For example:

   A B C D E F
1  _ _ X _ _ _  1 
2  O X X _ _ _  2
3  O X O O O O  3
4  O X O _ _ _  4
5  X X _ _ _ _  5
6  X O _ _ _ _  6
   A B C D E F

The player that attacks from north to south won (path/bridge from C to A).

My problem is: what algorithm would be good to check if the user has managed to complete a path (it will be checked at the end of each turn).

+1  A: 

This seems like a good application for a flood fill. Basically this would identify all the contiguous pieces of each player's pieces. You can check the min and max x (for the player trying to make a horizontal bridge) or the min and max y (for the player trying to make a vertical bridge) and if they are on opposite edges of the map, then the player has won.

miorel