Class Board

java.lang.Object
net.royalur.model.Board

public class Board extends Object
Stores the placement of pieces on the tiles of a Royal Game of Ur board.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Board(Board template)
    Instantiates a board with the same shape and pieces as template.
     
    Instantiates an empty board with the shape shape.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all pieces from this board.
    boolean
    contains(Tile tile)
    Determines whether tile falls within the bounds of this board.
    boolean
    containsIndices(int ix, int iy)
    Determines whether the tile at the indices (ix, iy), 0-based, falls within the bounds of this board.
    Creates an exact copy of this board.
    int
    Counts the number of pieces that are on the board for player.
    boolean
     
    get(Tile tile)
    Gets the piece on tile.
    getByIndices(int ix, int iy)
    Gets the piece on the tile at the indices (ix, iy), 0-based.
    int
    Gets the height of the board, which represents the number of y-coordinates in this board.
    Gets the shape of this board.
    int
    Gets the width of the board, which represents the number of x-coordinates in this board.
    set(Tile tile, Piece piece)
    Sets the piece on tile to piece.
    setByIndices(int ix, int iy, Piece piece)
    Sets the piece on the tile at the indices (ix, iy), 0-based, to the piece piece.
     
    toString(String columnDelimiter, boolean includeOffBoardTiles)
    Writes the contents of this board into a String, where each column is separated by a delimiter.

    Methods inherited from class java.lang.Object

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

    • Board

      public Board(BoardShape shape)
      Instantiates an empty board with the shape shape.
      Parameters:
      shape - The shape of this board.
    • Board

      protected Board(Board template)
      Instantiates a board with the same shape and pieces as template.
      Parameters:
      template - Another board to use as a template to copy from.
  • Method Details

    • copy

      public Board copy()
      Creates an exact copy of this board.
      Returns:
      An exact copy of this board.
    • getShape

      public BoardShape getShape()
      Gets the shape of this board.
      Returns:
      The shape of this board.
    • getWidth

      public int getWidth()
      Gets the width of the board, which represents the number of x-coordinates in this board.
      Returns:
      The number of x-coordinates that exist in this board.
    • getHeight

      public int getHeight()
      Gets the height of the board, which represents the number of y-coordinates in this board.
      Returns:
      The number of y-coordinates that exist in this board.
    • contains

      public boolean contains(Tile tile)
      Determines whether tile falls within the bounds of this board.
      Parameters:
      tile - The tile to be bounds-checked.
      Returns:
      Whether the given tile falls within the bounds of this board.
    • containsIndices

      public boolean containsIndices(int ix, int iy)
      Determines whether the tile at the indices (ix, iy), 0-based, falls within the bounds of this board.
      Parameters:
      ix - The x-index of the tile to be bounds-checked. This coordinate is 0-based.
      iy - The y-index of the tile to be bounds-checked. This coordinate is 0-based.
      Returns:
      Whether the given tile falls within the bounds of this board.
    • get

      @Nullable public Piece get(Tile tile)
      Gets the piece on tile. Returns null if there is no piece on the tile.
      Parameters:
      tile - The tile to find the piece on.
      Returns:
      The piece on the given tile if one exists, or else null.
    • getByIndices

      @Nullable public Piece getByIndices(int ix, int iy)
      Gets the piece on the tile at the indices (ix, iy), 0-based. Returns null if there is no piece on the tile.
      Parameters:
      ix - The x-index of the tile to find the piece on. This coordinate is 0-based.
      iy - The y-index of the tile to find the piece on. This coordinate is 0-based.
      Returns:
      The piece on the given tile if one exists, or else null.
    • set

      @Nullable public Piece set(Tile tile, @Nullable Piece piece)
      Sets the piece on tile to piece. If piece is null, it removes any piece on the tile. Returns the piece that was previously on the tile, or null if there was no piece on the tile.
      Parameters:
      tile - The tile to find the piece on.
      piece - The piece that should be placed on the tile.
      Returns:
      The previous piece on the given tile if there was one, or else null.
    • setByIndices

      @Nullable public Piece setByIndices(int ix, int iy, @Nullable Piece piece)
      Sets the piece on the tile at the indices (ix, iy), 0-based, to the piece piece. If piece is null, it removes any piece on the tile. Returns the piece that was previously on the tile, or null if there was no piece on the tile.
      Parameters:
      ix - The x-index of the tile to place the piece on. This coordinate is 0-based.
      iy - The y-index of the tile to place the piece on. This coordinate is 0-based.
      piece - The piece that should be placed on the tile.
      Returns:
      The previous piece on the given tile if there was one, or else null.
    • clear

      public void clear()
      Removes all pieces from this board.
    • countPieces

      public int countPieces(PlayerType player)
      Counts the number of pieces that are on the board for player.
      Parameters:
      player - The player to count the pieces of.
      Returns:
      The number of pieces on the board for the given player.
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString(String columnDelimiter, boolean includeOffBoardTiles)
      Writes the contents of this board into a String, where each column is separated by a delimiter.
      Parameters:
      columnDelimiter - The delimiter to use to distinguish columns of the board.
      includeOffBoardTiles - Whether to include tiles that don't fall on the board as spaces.
      Returns:
      A String representing the contents of this board.
    • toString

      public String toString()
      Overrides:
      toString in class Object