battleship

Safe HaskellSafe

BoardUntrusted

Contents

Description

This untrusted module implements the abstract type of shooting-phase boards. It also defines functions for describing boards as strings and lists of strings.

Synopsis

Shooting-phase Boards

data Board

Abstract type of shooting phase boards.

completeToBoard :: Complete -> Board

Turns a complete placing into a board on which no shooting has occurred.

allSunk :: Board -> Bool

Tests whether all ships of a board are sunk.

data ShotResult

Result of shooting at a board.

Constructors

Repeat

An attempt to shoot a position already shot.

Miss

Miss -- didn't hit ship.

Hit Ship

Hit a specified ship.

Sank Ship

Sank a specified ship -- last of its cells hit.

shoot :: Board -> Pos -> (Board, ShotResult)

Shoot a given position of a board, yielding a new board and a shot result. The shot result indicates the result of the shooting.

String Descriptions of Boards

placingToStrs :: Placing -> [String]

Convert a placing to a list of strings describing it. See MatrixUntrusted for the general format. Each cell of a ship is presented as the ship's first letter, in lowercase; vacant cells are presented as " ".

completeToStrs :: Complete -> [String]

Convert a complete placing to a list of strings describing it -- works identically to placingToStrs.

boardToStrs :: Board -> [String]

Convert a board to a list of strings describing it. See MatrixUntrusted for the general format.

  • Each vacant cell (not part of a ship) that's not been shot at is presented as " ".
  • Each vacant cell that's been shot at is labeled "*".
  • Each cell of a ship is presented as the ship's first letter: in lowercase, if that cell's not been hit; and in uppercase, if that cell has been hit.