Package cs251.lab2

Interface GomokuInterface


public interface GomokuInterface
This is the interface that describes the methods that must be present in the class you are writing that interfaces with the GUI. The game of Gomoku is very similar to tic-tac-toe, only that you are playing on a larger board, and the goal is to get five-in-a-row. You are allowed to place your marker anywhere there's an empty square on the board.
  • Field Details

    • DEFAULT_NUM_COLS

      static final int DEFAULT_NUM_COLS
      Default number of horizontal squares on the board
      See Also:
    • DEFAULT_NUM_ROWS

      static final int DEFAULT_NUM_ROWS
      Default number of vertical squares on the board
      See Also:
    • SQUARES_IN_LINE_FOR_WIN

      static final int SQUARES_IN_LINE_FOR_WIN
      Default squares in a line required for a win
      See Also:
  • Method Details

    • getNumCols

      int getNumCols()
      Get the number of columns for the game board. (If you aren't playing around with the board size, just return DEFAULT_NUM_COLS.)
      Returns:
      Number of horizontal squares on the board
    • getNumRows

      int getNumRows()
      Get the number of rows for the game board. (If you aren't playing around with the board size, just return DEFAULT_NUM_ROWS.)
      Returns:
      Number of vertical squares on the board
    • getNumInLineForWin

      int getNumInLineForWin()
      Get the number in a line needed for a win. (If you aren't playing around with the game rules, just return SQUARES_IN_LINE_FOR_WIN.)
      Returns:
      Number of squares in a line required for a win
    • handleClickAt

      GomokuInterface.TurnResult handleClickAt(int row, int col)
      Attempt a move at a given location on the board. This method is called when the user clicks in the board. If the square is already occupied, nothing about the state of the game changes. If however, an empty square is clicked, then it should be filled with a value representing the player currently in turn. On a failure, the turn doesn't change, but that player gets to go again. Called from the GUI.
      Parameters:
      row - 0-based row that was clicked
      col - 0-based column that was clicked
      Returns:
      State of this game after this move occurred
    • initializeGame

      void initializeGame()
      Initialize state for a new game. Starts a new game, resets the game board to empty. Pick a random player to go first the first time. In games after that, you should make it so that the player who won the last game gets to go first in the next round. This method is called by the GUI whenever a new game is supposed to be started, including before the first game when the program begins.
    • getCurrentBoardAsString

      String getCurrentBoardAsString()
      Get a string representation of the board. The characters are given by the Square.toChar method, so a hyphen in the string is an empty square, an uppercase 'O' represents the ring, and uppercase 'X' is the cross. Each line in the board is separated by a new line character '\n'. An example of a small board might look like this if viewed in a text file:
       OX--X
       XOXOO
       XXOOX
       OOXOX
       XOXOO
       
      In this case, O must have started, and just won the game through a diagonal.
      Returns:
      String representation of the board
    • getCurrentTurn

      GomokuInterface.Square getCurrentTurn()
      Get which player's turn it is. As long as the game as still going, will toggle between RING and CROSS after each successful move. Current turn does not change after the last move of the game.
      Returns:
      RING or CROSS, depending on current player.
    • initComputerPlayer

      void initComputerPlayer(String opponent)
      Configure whether a computer player will be used. At the very least, recognize the following options
      • NONE - no computer player (the default)
      • COMPUTER - one of the players is the computer
      It is permissible to have additional options if, for example, there are multiple computer player implementations to choose from. If the string is not a recognized computer player setting, print a message to the console and use the default no player setting.
      Parameters:
      opponent - String for computer player type.