Class Tile

java.lang.Object
net.royalur.model.Tile

public class Tile extends Object
A tile represents location on a Royal Game of Ur board.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Tile(int x, int y)
    Instantiates a tile location.
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<Tile>
    createList(int... coordinates)
    Constructs a list of tiles from the tile coordinates.
    static List<Tile>
    createPath(int... coordinates)
    Constructs a path from waypoints on the board.
    void
    Encodes the location of this tile into builder.
    void
    Encodes the x-coordinate as an upper-case letter, and appends it to builder.
    void
    Encodes the x-coordinate as a lower-case letter, and appends it to builder.
    void
    Encodes the y-coordinate as a number, and appends it to builder.
    boolean
     
    static Tile
    fromIndices(int ix, int iy)
    Creates a new tile representing the tile at the indices (ix, iy), 0-based.
    static Tile
    Converts text representations of the tile of the format "[letter][number]".
    int
    Gets the x-coordinate of the tile.
    int
    Gets the x-index of the tile.
    int
    Gets the y-coordinate of the tile.
    int
    Gets the y-index of the tile.
    int
     
    Takes a unit length step towards the other tile.
    Converts the location of this tile into a text representation of the format "[letter][number]".
    static Set<Tile>
    unionLists(Collection<Tile>... tileLists)
    Calculates the union of all given tile lists.

    Methods inherited from class java.lang.Object

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

    • Tile

      public Tile(int x, int y)
      Instantiates a tile location.
      Parameters:
      x - The x-coordinate of the tile. This coordinate starts at 1.
      y - The y-coordinate of the tile. This coordinate starts at 1.
  • Method Details

    • getX

      public int getX()
      Gets the x-coordinate of the tile. This coordinate is 1-based.
      Returns:
      The x-coordinate of the tile.
    • getXIndex

      public int getXIndex()
      Gets the x-index of the tile. This coordinate is 0-based.
      Returns:
      The x-index of the tile.
    • getY

      public int getY()
      Gets the y-coordinate of the tile. This coordinate is 1-based.
      Returns:
      The y-coordinate of the tile.
    • getYIndex

      public int getYIndex()
      Gets the y-index of the tile. This coordinate is 0-based.
      Returns:
      The y-index of the tile.
    • fromIndices

      public static Tile fromIndices(int ix, int iy)
      Creates a new tile representing the tile at the indices (ix, iy), 0-based.
      Parameters:
      ix - The x-index of the tile. This coordinate is 0-based.
      iy - The y-index of the tile. This coordinate is 0-based.
      Returns:
      A tile representing the tile at indices (ix, iy).
    • hashCode

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

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

      public Tile stepTowards(Tile other)
      Takes a unit length step towards the other tile.
      Parameters:
      other - The other vector to step towards.
      Returns:
      A new vector that is one step closer to other.
    • encode

      public void encode(StringBuilder builder)
      Encodes the location of this tile into builder.
      Parameters:
      builder - The builder to place the encoded tile coordinates into.
    • encodeX

      public void encodeX(StringBuilder builder)
      Encodes the x-coordinate as an upper-case letter, and appends it to builder.
      Parameters:
      builder - The builder to place the encoded x-coordinate into.
    • encodeXLowerCase

      public void encodeXLowerCase(StringBuilder builder)
      Encodes the x-coordinate as a lower-case letter, and appends it to builder.
      Parameters:
      builder - The builder to place the encoded x-coordinate into.
    • encodeY

      public void encodeY(StringBuilder builder)
      Encodes the y-coordinate as a number, and appends it to builder.
      Parameters:
      builder - The builder to place the encoded y-coordinate into.
    • toString

      public String toString()
      Converts the location of this tile into a text representation of the format "[letter][number]".
      Overrides:
      toString in class Object
      Returns:
      A text representation of the location of this tile.
    • fromString

      public static Tile fromString(String tile)
      Converts text representations of the tile of the format "[letter][number]". For example: - A1 represents (1, 1) - C3 represents (3, 3) - B8 represents (2, 8) - B0 represents (2, 0)
      Parameters:
      tile - The text representation of the tile's location.
      Returns:
      The tile that the given text is representing.
    • createList

      public static List<Tile> createList(int... coordinates)
      Constructs a list of tiles from the tile coordinates.
      Parameters:
      coordinates - The tile coordinates. Must be an even list ordered following x0, y0, x1, y1, x2, y2, etc.
      Returns:
      A list of tiles.
    • createPath

      public static List<Tile> createPath(int... coordinates)
      Constructs a path from waypoints on the board.
      Parameters:
      coordinates - The waypoint coordinates. Must be an even list ordered following x0, y0, x1, y1, x2, y2, etc.
      Returns:
      A list of tiles following the path between the given waypoints.
    • unionLists

      @SafeVarargs public static Set<Tile> unionLists(Collection<Tile>... tileLists)
      Calculates the union of all given tile lists.
      Parameters:
      tileLists - The lists of tiles.
      Returns:
      A set of all tiles.