Battleship ========== The Battleship Service provides helpful utilities for building a distributed game of battleship. Overview -------- Like regular Battleship, the Battleship service has two states: placing ships and shooting at ships. During placement, it expects each role to place each ship on his/her board and will not allow the game to proceed to the shooting phase until each role has placed all his/her ships. Placement, firing and starting blocks will return true if successful or an error message if it fails. Blocks ------ - ``place at facing `` - Places a ship on your board with the front at the given row and column facing the given direction. Returns ``true`` if placed successfully (eg, on the board and not overlapping another ship). Also, placing a ship twice results in a move (not duplicates). - ``start game`` - Try to start the game. If both users have all their ships placed, it should return true and send ``start`` messages to all roles. Otherwise, it will return with a message saying that it is waiting on a specific role. - ``fire at `` - This block allows the user to try to fire at the given row and column. It returns ``true`` if it was a valid move; otherwise it will return an error message like ``it's not your turn!``. On a successful move, the server will send either a ``hit`` or ``miss`` message to everyone in the room. Then it will send a ``your turn`` message to the player to play next. - ``active ships for `` - This block returns a list of all ships that are still afloat for the given role. If no role is specified, it defaults to the sender's role. - ``all ships`` - Returns a list of all ship names. Useful in programmatically placing ships. - ``ship length `` - Returns the length of the given ship. - ``restart game`` - Restarts the given game (all boards, etc) Message Types ------------- - ``start`` - Received when ``start game`` finishes successfully for any role. After game has officially started, users can no longer move ships. - ``your turn`` - Received when the given role's turn starts. - ``hit`` - ``role`` is the owner of the ship that has been hit. ``ship`` is the name of the ship that has been hit, and ``row`` and ``column`` provide the location on the board where it was hit. ``sunk`` provides a true/false value for if the ship was sunk. - ``miss`` - ``role`` is the owner of the board receiving the shot and ``row`` and ``column`` correspond to the board location or the shot. .. toctree:: :maxdepth: 2 :titlesonly: :caption: RPC Categories RPCS ---- .. function:: Battleship.allShips() Get list of ship types **Returns:** ``List`` (`List `__ | `String `__) - Types of ships .. function:: Battleship.fire(row: BoundedNumber<1, 100>, column: BoundedNumber<1, 100>) Fire a shot at the board **Arguments:** - ``row: BoundedNumber<1, 100>`` (`BoundedNumber `__) - Row to fire at - ``column: BoundedNumber<1, 100>`` (`BoundedNumber `__) - Column to fire at **Returns:** ``Boolean`` (`Boolean `__) - If ship was hit .. function:: Battleship.placeShip(ship: String, row: BoundedNumber<1, 100>, column: BoundedNumber<1, 100>, facing: String) Place a ship on the board **Arguments:** - ``ship: String`` (`String `__) - Ship type to place - ``row: BoundedNumber<1, 100>`` (`BoundedNumber `__) - Row to place ship in - ``column: BoundedNumber<1, 100>`` (`BoundedNumber `__) - Column to place ship in - ``facing: String`` (`String `__) - Direction to face **Returns:** ``Boolean`` (`Boolean `__) - If piece was placed .. function:: Battleship.remainingShips(roleID: String) Get number of remaining ships of a role **Arguments:** - ``roleID: String`` (`String `__) - Name of role to use **Returns:** ``Integer`` (`Integer `__) - Number of remaining ships .. function:: Battleship.reset() Resets the game by clearing the board and reverting to the placing phase **Returns:** ``Boolean`` (`Boolean `__) - If game was reset .. function:: Battleship.shipLength(ship: String) Get length of a ship type **Arguments:** - ``ship: String`` (`String `__) - Type of ship **Returns:** ``Integer`` (`Integer `__) - Length of ship type .. function:: Battleship.start() Begins the game, if board is ready **Returns:** ``Boolean`` (`Boolean `__) - If game was started