University of Arizona, Department of Computer Science

CSc 120: Battleship: Rules

Legal Placement

In order for a placement to be legal, each of the five ships must be placed legally. A ship placement with endpoints (x1, y1) and (x2, y2) is legal if all of the following conditions are satisfied:

  1. The ship must either be parallel to the x axis or else parallel to the y axis.

  2. The ship must be contained within the 10x10 grid of the game board, i.e., 0 ≤ x1, y1, x2, y2 ≤ 9.

  3. The distance between the end-points (x1, y1) and (x2, y2) must match the size of the ship.

  4. Each grid point (x, y) occupied by the ship, i.e., including and lying between the end-points (x1, y1) and (x2, y2), cannot be occupied by any other ship.

The following illustrates examples of legal and illegal placements:

examples of legal and illegal placement

Legal Guesses

A guess x, y is legal if it is within the game board, i.e.,
0 ≤ x, y ≤ 9