BattleShip Game
Battleship is a game played between 2 players. Each player will be initialised with an M * M
grid with S number of the ships placed at specified positions on the grid.
One battleship occupies a single position on the Grid.
Objective of the game is to destroy opponent’s ships. Each player will
be given T number of missiles.
Based on hits/misses of a missile on the opponent, either of the player might be vistorious or the game might end as a draw.
go get -u github.com/vedhavyas/battleship/cmd/battleship/...
cd $GOPATH/bin
./battleship --help
Program requires an Input file
and an Output file
.
Input file should be of the following format
Since it was not specifically mentioned in the problem as to how the coordinate system of the
board works. Hence, we are assuming that (0,0) lies in the top left corner and (m,m) in bottom right.
Final depiction of the board looks as follows
(0,0) (0,1) (0,2)
(1,0) _ _ _
(2,0) _ _ _
Program requires an output file to write the result back to the file.
If file does not exist, one will be created.
If file exists, then the data is overwritten
Programs sample output in the Output File
will look as follows.
Player1
O O _ _ _
_ B O _ _
B _ _ X _
_ _ _ _ B
_ _ _ X _
Player2
_ X _ _ _
_ _ _ _ _
_ _ _ X _
B O _ _ B
_ X _ O _
P1: 3
P2: 2
Player1 wins