Package edu.uky.ai.tic.state

# Class State

java.lang.Object
edu.uky.ai.tic.state.State

    public class State
    extends java.lang.Object

Represents the current state of a Tic Tac Toe game.

Author:
  Stephen G. Ware

- ## Constructor Summary

  Constructors
  Constructor | Description
  --- | ---
  `State()` | Constructs the initial state of all Tic Tac Toe games, in which the grid is empty and it is X's turn to move.

- ## Method Summary

  Modifier and Type | Method | Description
  --- | --- | ---
  `java.lang.Iterable<Move>` | `getAvailableMoves()` | Returns a set of all the next moves that can be made in the game.
  `Player` | `getCurrentPlayer()` | Returns the player whose turn it is to move next.
  `Player` | `getSquare​(int row, int column)` | Returns the mark at the given row and column of the grid.
  `Player` | `getWinner()` | Returns the winner, if one has been determined.
  `boolean` | `isTerminal()` | Returns true if a winner has been decided or if the game is a tie.
  `java.lang.String` | `toString()` |
  `State` | `transition​(Move move)` | Returns the state that would result from taking the given move.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### State

    public State()
    Constructs the initial state of all Tic Tac Toe games, in which the grid is empty and it is X's turn to move.

- ## Method Details

  - ### getCurrentPlayer

    public Player getCurrentPlayer()
    Returns the player whose turn it is to move next.
    Returns:
      the current player

  - ### getSquare

    public Player getSquare​(int row, int column)
    Returns the mark at the given row and column of the grid.
    Parameters:
      `row` - the row number (0 to 2)
      `column` - the column number (0 to 2)
    Returns:
      the player who has placed a mark at that location, or null if no player has placed a mark in that location

  - ### getAvailableMoves

    public java.lang.Iterable<Move> getAvailableMoves()
    Returns a set of all the next moves that can be made in the game.
    Returns:
      all possible next moves

  - ### transition

    public State transition​(Move move)
    Returns the state that would result from taking the given move. Note that this object remains unchanged.
    Parameters:
      `move` - the move to take
    Returns:
      the resulting state

  - ### isTerminal

    public boolean isTerminal()
    Returns true if a winner has been decided or if the game is a tie.
    Returns:
      true if the game is over, false otherwise

  - ### getWinner

    public Player getWinner()
    Returns the winner, if one has been determined.
    Returns:
      the winning player, or null if no player has won or the game ended in a tie

  - ### toString

    public java.lang.String toString()
    Overrides:
      `toString` in class `java.lang.Object`