Class TicTacToe

java.lang.Object
net.flectone.pulse.module.command.tictactoe.model.TicTacToe

public class TicTacToe extends Object
A game of tic-tac-toe, including the moves played and who is to move next.
  • Field Details

    • FIRST_VALUE

      public static final int FIRST_VALUE
      The board value marking the first player's move.
      See Also:
    • SECOND_VALUE

      public static final int SECOND_VALUE
      The board value marking the second player's move.
      See Also:
    • REMOVE_MULTIPLIER

      public static final int REMOVE_MULTIPLIER
      Applied to a board value to mark the move that hard mode is about to drop.
      See Also:
    • WIN_OFFSET

      public static final int WIN_OFFSET
      Added to a board value to mark a square that is part of the winning line.
      See Also:
  • Constructor Details

    • TicTacToe

      public TicTacToe(int id, int firstPlayer, int secondPlayer, boolean hard)
      Creates a game.
      Parameters:
      id - the game id
      firstPlayer - the player who moves first
      secondPlayer - the other player
      hard - whether the older move is removed once a player has three on the board
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isWin

      public boolean isWin()
      Whether the last move completed a line.
      Returns:
      true if the game is won
    • checkWinningTrio

      public void checkWinningTrio()
      Looks for a completed line and records it, so it can be highlighted on the board.
    • isDraw

      public boolean isDraw()
      Whether the board is full with no line completed.
      Returns:
      true if the game is drawn
    • contains

      public boolean contains(FPlayer fPlayer)
      Whether a player is in this game.
      Parameters:
      fPlayer - the player
      Returns:
      true if they are one of the two
    • setNextPlayer

      public void setNextPlayer()
      Passes the turn to the other player.
    • move

      public boolean move(FPlayer fPlayer, String move)
      Plays a square, and in hard mode drops that player's oldest move.
      Parameters:
      fPlayer - the player moving
      move - the square, written as its row and column
      Returns:
      true if the move was legal
    • getMovesMap

      public LinkedHashMap<Integer, Queue<String>> getMovesMap()
    • getId

      public int getId()
    • isHard

      public boolean isHard()
    • getField

      public int[][] getField()
    • getFirstPlayer

      public int getFirstPlayer()
    • getSecondPlayer

      public int getSecondPlayer()
    • getNextPlayer

      public int getNextPlayer()
    • getWinningTrio

      public int[] getWinningTrio()
    • isEnded

      public boolean isEnded()
    • isCreated

      public boolean isCreated()
    • setNextPlayer

      public void setNextPlayer(int nextPlayer)
    • setEnded

      public void setEnded(boolean ended)