Interface Board

All Known Implementing Classes:
BitBoard

public interface Board
A Connect Four board, containing information about who has played at every location.
Author:
Finn Voichick
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int HEIGHT
    The height of any board, equivalent to the number of rows.
    static int WIDTH
    The width of any board, equivalent to the number of columns.
  • Method Summary

    Modifier and Type Method Description
    boolean canPlay​(int column)
    Determines if it is legal for the current player to play a piece in the given column.
    Board createNextBoard​(int column)
    Creates a new Board object that contains one additional piece.
    java.util.Optional<Player> get​(BoardLocation location)
    Gets the player who has played at the given location.
    Player getCurrentPlayer()
    Gets the player who is currently up to play.
    int getTurnsPlayed()
    Gets the number of turns that have been played since the start of the game.
    java.util.Set<java.lang.Integer> getValidPlays()
    Gets a set of columns that are valid plays for the current player.
    java.util.Optional<Player> getWinner()
    Gets the player who has won the game.
    boolean isFull()
    Determines whether or not this board is completely full.
    default boolean isGameOngoing()  
    default boolean isGameOver()  
  • Field Details

  • Method Details

    • get

      java.util.Optional<Player> get​(BoardLocation location)
      Gets the player who has played at the given location. If nobody has played at the given location, this method returns empty.
      Parameters:
      location - the location in the board to examine
      Returns:
      the player who played there, or empty
    • getCurrentPlayer

      Player getCurrentPlayer()
      Gets the player who is currently up to play. This will be the opponent of the player who has just played.
      Returns:
      the player whose turn it is
    • canPlay

      boolean canPlay​(int column)
      Determines if it is legal for the current player to play a piece in the given column. A column is a legal play if it is not full.
      Parameters:
      column - the column that is questionably full
      Returns:
      true if the given column is not full, otherwise false
    • getValidPlays

      java.util.Set<java.lang.Integer> getValidPlays()
      Gets a set of columns that are valid plays for the current player. In other words, this set contains all integers for which the canPlay(int) method would return true.
      Returns:
      the set of all valid moves for the current player
    • createNextBoard

      Board createNextBoard​(int column)
      Creates a new Board object that contains one additional piece. The current player of this next board will be the opponent of the current board.
      Parameters:
      column - the column in which to play
      Returns:
      the new board
    • isFull

      boolean isFull()
      Determines whether or not this board is completely full. A board is full if each of its columns is full, and getValidPlays() would return an empty set.
      Returns:
      true if the board is completely filled in otherwise false
    • getWinner

      java.util.Optional<Player> getWinner()
      Gets the player who has won the game. If nobody has won, empty is returned.
      Returns:
      the player who has won, or empty
    • getTurnsPlayed

      int getTurnsPlayed()
      Gets the number of turns that have been played since the start of the game. For an empty board, this will return 0. If one player has played, this will return 1. In other words, this is equivalent to the number of pieces on the board.
      Returns:
      the number of turns that have been played since the start of the game
    • isGameOver

      default boolean isGameOver()
    • isGameOngoing

      default boolean isGameOngoing()