Class TicTacToe

java.lang.Object
com.zybooks.dsaj.fundamental.TicTacToe

public class TicTacToe extends Object
Simulation of a Tic-Tac-Toe game (does not do strategy).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the board
    boolean
    isWin(int mark)
    Checks whether the board configuration is a win for the given player.
    static void
    main(String[] args)
    Test run of a simple game
    void
    putMark(int i, int j)
    Puts an X or O mark at position i,j.
    Returns a simple character string showing the current board.
    int
    Returns the winning player's code, or 0 to indicate a tie (or unfinished game).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • TicTacToe

      public TicTacToe()
      Constructor
  • Method Details

    • clearBoard

      public void clearBoard()
      Clears the board
    • putMark

      public void putMark(int i, int j) throws IllegalArgumentException
      Puts an X or O mark at position i,j.
      Throws:
      IllegalArgumentException
    • isWin

      public boolean isWin(int mark)
      Checks whether the board configuration is a win for the given player.
    • winner

      public int winner()
      Returns the winning player's code, or 0 to indicate a tie (or unfinished game).
    • toString

      public String toString()
      Returns a simple character string showing the current board.
      Overrides:
      toString in class Object
    • main

      public static void main(String[] args)
      Test run of a simple game