This preview shows page 1. Sign up to view the full content.
Unformatted text preview: member that if a ship is facing north,
the rest of the ship is to the south of the bow. A ship may not go over the edges of the grid, and may not
occupy an already occupied space. How a ship is represented in the grid will be described later. each
ship will have a unique index described below.
Returns the index of the placed ship, if the placement was successful, and 'None' otherwise. If ship
placement was not successful, the board should not have been modified.
Implement f r , a function with 2 arguments: The b a d to fire on, and a tuple (x,y)
or representing the t r e o fire on. If the target is an illegal target, return None.
Otherwise returns atuple (hit,ship), where hit is True/False depending if the the shot hit, and ship
is the index of the ship which was completely destroyed, or 0 if no ship was completely destroyed.
Each cell in the grid contains one of the following:
1. None, if the cell has no ship.
2. A tuple (index,part,[size]), where index is the index of the s...
View Full Document
- Spring '14