Package Jade

Class Grid

java.lang.Object
Jade.Grid
All Implemented Interfaces:
jade.util.leap.Serializable, Serializable

public class Grid extends Object implements jade.util.leap.Serializable
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    getCell(int num)
    Returns the cell symbol at the specified position in the grid, using the grid indexing convention.
    getCell(int row, int col)
    Returns the cell symbol at the specified position in the grid.
    Returns the free cells.
    String[][]
    Returns the grid.
    Returns the symbol of the winner in the grid.
    boolean
    Check if the grid contains a draw.
    boolean
    Checks if the grid is empty.
    boolean
    isFree(int row, int col)
    Checks if a move is legal in the grid, using the grid indexing convention.
    boolean
    Checks if the grid is full.
    boolean
    isLegal(int row, int col)
    Checks if a move is legal in the grid.
    boolean
    isMySymbolThere(int row, int col, String symbol)
    Check if the symbol "symbol" is in the grid at the specified position.
    boolean
    Checks if somebody has won in the grid.
    void
    Prints the grid in a nice way.
    boolean
    setCell(int row, int col, String value)
    Sets the cell symbol at the specified position in the grid.
    boolean
    setCell(int num, String value)
    Sets the cell symbol at the specified position in the grid, using the grid indexing convention.
    void
    setGrid(Grid grid)
    Sets the grid.
    Returns the grid as a string.

    Methods inherited from class java.lang.Object

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

    • Grid

      public Grid()
  • Method Details

    • getCell

      public String getCell(int row, int col)
      Returns the cell symbol at the specified position in the grid.
      Parameters:
      row -
      col -
      Returns:
      String
    • getCell

      public String getCell(int num)
      Returns the cell symbol at the specified position in the grid, using the grid indexing convention.
      Parameters:
      num -
      Returns:
      String
    • setCell

      public boolean setCell(int row, int col, String value)
      Sets the cell symbol at the specified position in the grid. First, we check if the cell is free, using the isLegal(row, col) method. If it is, we set the cell symbol.
      Parameters:
      row -
      col -
      value -
      Returns:
      boolean
    • setCell

      public boolean setCell(int num, String value)
      Sets the cell symbol at the specified position in the grid, using the grid indexing convention.
      Parameters:
      num -
      value -
      Returns:
      boolean
    • isFull

      public boolean isFull()
      Checks if the grid is full.
      Returns:
      boolean
    • isEmpty

      public boolean isEmpty()
      Checks if the grid is empty.
      Returns:
      boolean
    • isDraw

      public boolean isDraw()
      Check if the grid contains a draw.
      Returns:
      boolean
    • isWinner

      public boolean isWinner()
      Checks if somebody has won in the grid.
      Returns:
      boolean
    • getWinner

      public String getWinner()
      Returns the symbol of the winner in the grid.
      Returns:
      String
    • isLegal

      public boolean isLegal(int row, int col)
      Checks if a move is legal in the grid.
      Parameters:
      row -
      col -
      Returns:
      boolean
    • isFree

      public boolean isFree(int row, int col)
      Checks if a move is legal in the grid, using the grid indexing convention.
      Parameters:
      row -
      col -
      Returns:
      boolean
    • isMySymbolThere

      public boolean isMySymbolThere(int row, int col, String symbol)
      Check if the symbol "symbol" is in the grid at the specified position.
      Parameters:
      row -
      col -
      symbol -
      Returns:
      boolean
    • getGrid

      public String[][] getGrid()
      Returns the grid.
      Returns:
      String[][]
    • getFreeCells

      public List<Integer> getFreeCells()
      Returns the free cells.
      Returns:
      List
    • setGrid

      public void setGrid(Grid grid)
      Sets the grid.
      Parameters:
      grid -
    • printGrid

      public void printGrid()
      Prints the grid in a nice way.
    • toString

      public String toString()
      Returns the grid as a string.
      Overrides:
      toString in class Object
      Returns:
      String