Package cpsc2150.extendedConnectX.models

# Interface IGameBoard

All Known Implementing Classes:
  `AbsGameBoard`, `GameBoard`, `GameBoardMem`

public interface IGameBoard
Interface that contains methods for implementing an entire game board for the ExtendedConnectX game.

This interface includes methods to place tokens, check token locations, and determine whether or not the game has been won or is over.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `MAX_COLUMNS`
  `static final int`
  `MAX_NUM_TO_WIN`
  `static final int`
  `MAX_ROWS`
  `static final int`
  `MIN_COLUMNS`
  `static final int`
  `MIN_NUM_TO_WIN`
  `static final int`
  `MIN_ROWS`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default boolean`
  `checkDiagWin(BoardPosition pos, char p)`
  This function checks to see if the last token placed (which was placed in position pos by player p) resulted in 5 in a row diagonally.
  `default boolean`
  `checkForWin(int c)`
  This function will check to see if the last token placed in column c resulted in the player winning the game.
  `default boolean`
  `checkHorizWin(BoardPosition pos, char p)`
  This function checks to see if the last token placed (which was placed in position pos by player p) resulted in 5 in a row horizontally.
  `default boolean`
  `checkIfFree(int c)`
  Function that returns true if the column can accept another token; false otherwise.
  `default boolean`
  `checkTie()`
  This function will check to see if the game has resulted in a tie.
  `default boolean`
  `checkVertWin(BoardPosition pos, char p)`
  This function checks to see if the last token placed (which was placed in position pos by player p) resulted in 5 in a row vertically.
  `int`
  `getNumColumns()`
  Returns the number of columns in the GameBoard.
  `int`
  `getNumRows()`
  Returns the number of rows in the GameBoard.
  `int`
  `getNumToWin()`
  Returns the number of tokens in a row needed to win the game.
  `default boolean`
  `isPlayerAtPos(BoardPosition pos, char player)`
  This function returns true if the player is at pos; otherwise, it returns false.
  `void`
  `placeToken(char p, int c)`
  Function that places the character p in column c.
  `char`
  `whatsAtPos(BoardPosition pos)`
  Function that returns what is in the GameBoard at position pos.

- ## Field Details

  - ### MIN_ROWS

    static final int MIN_ROWS
    See Also:
      - Constant Field Values

  - ### MAX_ROWS

    static final int MAX_ROWS
    See Also:
      - Constant Field Values

  - ### MIN_COLUMNS

    static final int MIN_COLUMNS
    See Also:
      - Constant Field Values

  - ### MAX_COLUMNS

    static final int MAX_COLUMNS
    See Also:
      - Constant Field Values

  - ### MIN_NUM_TO_WIN

    static final int MIN_NUM_TO_WIN
    See Also:
      - Constant Field Values

  - ### MAX_NUM_TO_WIN

    static final int MAX_NUM_TO_WIN
    See Also:
      - Constant Field Values

- ## Method Details

  - ### checkIfFree

    default boolean checkIfFree(int c)
    Function that returns true if the column can accept another token; false otherwise.
    Parameters:
      `c` - Column to be checked
    Returns:
      Whether the column can accept another token
    Pre:
      0 `<=` c `<` number_of_columns
    Post:
      checkIfFree = true iff ([ #self at column c and row number_of_rows - 1 ] = 'X' OR [ #self at column c and row number_of_rows - 1 ] = 'O') AND self = #self checkIfFree = false iff ([ #self at column c and row number_of_rows - 1 ] = ' ') AND self = #self

  - ### placeToken

    void placeToken(char p, int c)
    Function that places the character p in column c. The token will be placed in the lowest available row in column c.
    Parameters:
      `p` - Character to be placed (representing player token)
      `c` - Column to place token in
    Pre:
      (p = 'X' OR p = 'O') AND 0 `<=` c `<` number_of_columns
    Post:
      [ #self at column c and lowest available row ] = 'X' OR [ #self at column c and lowest available row ] = 'O' AND [ token is placed at the lowest available row ] AND [ self = #self plus the new token ]

  - ### checkForWin

    default boolean checkForWin(int c)
    This function will check to see if the last token placed in column c resulted in the player winning the game. If so it will return true, otherwise false.
    Parameters:
      `c` - Column number to be checked
    Returns:
      Whether placing a token results in a player winning the game
    Pre:
      0 `<=` c `<` number_of_columns AND [ c is the column where the latest token was placed ]
    Post:
      checkForWin = true iff (checkTie = false AND (checkHorizWin = true OR checkVertWin = true OR checkDiagWin = true) WHERE [ c is the column with the last placed token ] AND self = #self checkForWin = false iff (checkTie = true OR (checkHorizWin = false AND checkVertWin = false AND checkDiagWin = false) WHERE [ c is the column with the last placed token ] AND self = #self

  - ### checkTie

    default boolean checkTie()
    This function will check to see if the game has resulted in a tie. A game is tied if there are no free board positions remaining. It will return true if the game is tied and false otherwise.
    Returns:
      Whether the game has resulted in a tie
    Pre:
      [ the game has not ended with a win yet ]
    Post:
      checkTie = true iff ([all board positions are not ' ']) AND self = #self checkTie = false iff ([not all board positions are not ' ']) AND self = #self

  - ### checkHorizWin

    default boolean checkHorizWin(BoardPosition pos, char p)
    This function checks to see if the last token placed (which was placed in position pos by player p) resulted in 5 in a row horizontally. Returns true if it does, otherwise false.
    Parameters:
      `pos` - BoardPosition pair of row and column
      `p` - Player to check with
    Returns:
      Whether the last token placed resulted in 5 in a row horizontally
    Pre:
      (0 `>=` pos.row `<` number_of_rows AND 0 `>=` pos.column `<` number_of_columns) AND p != ' ' AND [ pos is the game board position on the latest play ] AND [ p is the token located at position pos ]
    Post:
      checkHorizWin = true iff ([num_to_win horizontal positions are p]) AND self = #self checkHorizWin = true iff ([num_to_win horizontal positions are not p]) AND self = #self

  - ### checkVertWin

    default boolean checkVertWin(BoardPosition pos, char p)
    This function checks to see if the last token placed (which was placed in position pos by player p) resulted in 5 in a row vertically. Returns true if it does, otherwise false.
    Parameters:
      `pos` - BoardPosition pair of row and column
      `p` - Player to check with
    Returns:
      Whether the last token placed resulted in 5 in a row vertically
    Pre:
      (0 `>=` pos.row `<` number_of_rows AND 0 `>=` pos.column `<` number_of_columns) AND p != ' ' AND [ pos is the game board position on the latest play ] AND [ p is the token located at position pos ]
    Post:
      checkVertWin = true iff ([num_to_win vertical positions are p]) AND self = #self checkVertWin = true iff ([num_to_win vertical positions are not p]) AND self = #self

  - ### checkDiagWin

    default boolean checkDiagWin(BoardPosition pos, char p)
    This function checks to see if the last token placed (which was placed in position pos by player p) resulted in 5 in a row diagonally. Returns true if it does, otherwise false.
    Parameters:
      `pos` - BoardPosition pair of row and column
      `p` - Player to check with
    Returns:
      Whether the last token placed resulted in 5 in a row diagonally
    Pre:
      (0 `>=` pos.row `<` number_of_rows AND 0 `>=` pos.column `<` number_of_columns) AND p != ' ' AND [ pos is the game board position on the latest play ] AND [ p is the token located at position pos ]
    Post:
      checkVertWin = true iff ([num_to_win diagonal positions are p]) AND self = #self checkVertWin = true iff ([num_to_win diagonal positions are not p]) AND self = #self

  - ### whatsAtPos

    char whatsAtPos(BoardPosition pos)
    Function that returns what is in the GameBoard at position pos. If no marker is there, it returns a blank space char.
    Parameters:
      `pos` - BoardPosition pair of row and column
    Returns:
      Character representing player token or space
    Pre:
      (0 `>=` pos.row `<` number_of_rows AND 0 `>=` pos.column `<` number_of_columns)
    Post:
      whatsAtPos = [ board at row pos.row and column pos.col ] AND self = #self

  - ### isPlayerAtPos

    default boolean isPlayerAtPos(BoardPosition pos, char player)
    This function returns true if the player is at pos; otherwise, it returns false.
    Parameters:
      `pos` - BoardPosition pair of row and column
      `player` - Player to check with
    Returns:
      Whether a player's token is at a position
    Pre:
      (0 `>=` pos.row `<` number_of_rows AND 0 `>=` pos.column `<` number_of_columns) AND player != ' '
    Post:
      isPlayerAtPos = true iff ([ board at row pos.row and column pos.col ] = player) AND self = #self isPlayerAtPos = false iff ([ board at row pos.row and column pos.col ] != player) AND self = #self

  - ### getNumRows

    int getNumRows()
    Returns the number of rows in the GameBoard.
    Returns:
      The number of rows
    Post:
      getNumRows = number_of_rows AND self = #self

  - ### getNumColumns

    int getNumColumns()
    Returns the number of columns in the GameBoard.
    Returns:
      The number of columns
    Post:
      getNumColumns = number_of_columns AND self = #self

  - ### getNumToWin

    int getNumToWin()
    Returns the number of tokens in a row needed to win the game.
    Returns:
      The number of tokens
    Post:
      getNumToWin = num_to_win AND self = #self