项目作者: vedhavyas

项目描述 :
BattleShip Game
高级语言: Go
项目地址: git://github.com/vedhavyas/battleship.git
创建时间: 2017-02-24T18:59:55Z
项目社区:https://github.com/vedhavyas/battleship

开源协议:Apache License 2.0

下载


BattleShips

  • 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.

Installation

  1. go get -u github.com/vedhavyas/battleship/cmd/battleship/...
  2. cd $GOPATH/bin
  3. ./battleship --help

Input

Program requires an Input file and an Output file.

Input File

Input file should be of the following format

  1. GridSize (0<M<10)
  2. Number of ships for each player
  3. Player 1 ship positions, should be of format x1,y1:x2,y2:x3,y3:x4,y4
  4. Player 2 ship positions, should be of format x1,y1:x2,y2:x3,y3:x4,y4
  5. Total number of missiles for each player (0<T<100)
  6. Player 1 Moves, should be of format x1,y1:x2,y2:x3,y3:x4,y4
  7. Player 2 Moves, should be of format x1,y1:x2,y2:x3,y3:x4,y4

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

  1. (0,0) (0,1) (0,2)
  2. (1,0) _ _ _
  3. (2,0) _ _ _

Output file

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

Output

Programs sample output in the Output File will look as follows.

  1. Player1
  2. O O _ _ _
  3. _ B O _ _
  4. B _ _ X _
  5. _ _ _ _ B
  6. _ _ _ X _
  1. Player2
  2. _ X _ _ _
  3. _ _ _ _ _
  4. _ _ _ X _
  5. B O _ _ B
  6. _ X _ O _
  1. P1: 3
  2. P2: 2
  3. Player1 wins
  • O - represents a missed hit by the opponent
  • B - represents a safe/un-hit ship of the player
  • X - represents a confirmed hit by the opponent
  • _ - represnets an empty location