Interface BattleshipStrategy

All Known Implementing Classes:
BruteforceStrategy, RandomStrategy

public interface BattleshipStrategy
An implementation of this interface represents a "strategy" or a computer A.I. player for the classic board game "Battleship".
  • Method Summary

    Modifier and Type
    Method
    Description
    callNextShot(GameState currentGameState)
    The main "play" method for this strategy--called when it is this player's turn to call out a shot on the opponent's board to try to hit one of the opponent's ships.
    boolean
    In some games, strategies that wish to may play "deviously", meaning they will reposition their ships when allowed.
    Gets the name of this player/strategy.
    void
    Called to initialize (or re-initialize) this strategy to play a new game.
    placeShips(GameState currentGameState)
    Called when this strategy can place its ships on the board, so that it can indicate where it wants its ships to go (typically at the start of a game).
  • Method Details

    • getName

      String getName()
      Gets the name of this player/strategy.
      Returns:
      This strategy's name.
    • newGame

      void newGame()
      Called to initialize (or re-initialize) this strategy to play a new game. This method is called before a game begins. The same strategy might play multiple games over time, and this is how the strategy is "reset" before the start of the game it is about to play right now.
    • placeShips

      ShipPlacementMove placeShips(GameState currentGameState)
      Called when this strategy can place its ships on the board, so that it can indicate where it wants its ships to go (typically at the start of a game). Note that in some "devious" versions of the game, this might be called more than once, giving a strategy a chance to reposition its ships after the opponent has called a shot. In that situation, the new ship placement must remain consistent with all the hits/misses scored by the opponent in all previous turns.
      Parameters:
      currentGameState - The current state of this player's board and the opponent's board.
      Returns:
      The new ship placement this strategy wants to use.
    • callNextShot

      CallShotMove callNextShot(GameState currentGameState)
      The main "play" method for this strategy--called when it is this player's turn to call out a shot on the opponent's board to try to hit one of the opponent's ships.
      Parameters:
      currentGameState - The current state of this player's board and the opponent's board.
      Returns:
      The next shot this strategy is calling (this strategy's next move).
    • canPlayDeviously

      boolean canPlayDeviously()
      In some games, strategies that wish to may play "deviously", meaning they will reposition their ships when allowed. Ships can be repositioned as long as sunken ships don't move and as long as the new position of each ship does not occupy any MISSes, and occupies the same number of HITs as before.
      Returns:
      True if this strategy is able to reposition its ships when allowed to play deviously, or false if it is not designed to be devious and expects to leave its ships in the same position for the entire game.