Package a5.logic

Class Board

java.lang.Object
a5.logic.Board

public class Board extends Object
A mutable representation of an m-by-n board in which each cell can be occupied by a player or be empty
  • Constructor Summary

    Constructors
    Constructor
    Description
    Board(int rowSize, int colSize)
    Creates a new rowSize-by-colSize board.
    Board(Board board)
    Creates a new board that deep copies a provided board.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    boolean
    Board equality is determined using state equality.
    protected void
    Effect: set the cell at position p to empty.
    int
    Returns: the board state of a cell.
    int
     
    boolean
    Returns: true if p is within the board.
    protected void
    place(Position p, PlayerRole currentPlayer)
    Effect: place a stone as currentPlayer on board at position p.
    int
     
    boolean
    Returns: true if p is a valid cell to place stones.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Board

      public Board(int rowSize, int colSize)
      Creates a new rowSize-by-colSize board.
    • Board

      public Board(Board board)
      Creates a new board that deep copies a provided board.
      Parameters:
      board - the board to copy from
  • Method Details

    • get

      public int get(Position p)
      Returns: the board state of a cell. Returns 0 if it is empty; otherwise, the returned value matches the player role's boardValue. Requires: p is on board
      Parameters:
      p - the position of the cell
    • place

      protected void place(Position p, PlayerRole currentPlayer)
      Effect: place a stone as currentPlayer on board at position p. Requires: p is on board and get(p) == 0
      Parameters:
      p - the position to place a stone
      currentPlayer - role of the current player
    • erase

      protected void erase(Position p)
      Effect: set the cell at position p to empty. Requires: p is on board
    • rowSize

      public int rowSize()
    • colSize

      public int colSize()
    • equals

      public boolean equals(Object o)
      Board equality is determined using state equality.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • validPos

      public boolean validPos(Position p)
      Returns: true if p is a valid cell to place stones.
    • onBoard

      public boolean onBoard(Position p)
      Returns: true if p is within the board.