package j2048;

/**
 * A data structure representing a point on the grid. This point may or may not
 * contain a tile. This class is immutable.
 * 
 * @author William Chargin
 * 
 */
public final class BoardLocation {

	/**
	 * The {@code x}-position of this location in the grid. The leftmost cells
	 * in the grid have {@code x}-position {@code 0}.
	 */
	private final int x;

	/**
	 * The {@code y}-position of this location in the grid. The topmost cells in
	 * the grid have {@code y}-position {@code 0}.
	 */
	private final int y;

	/**
	 * Creates a location with the given coordinates. The coordinates must be
	 * non-negative (greater than or equal to zero).
	 * 
	 * @param x
	 *            the {@code x}-position for this tile
	 * @param y
	 *            the {@code y}-position for this tile
	 * @throws IllegalArgumentException
	 *             if {@code x < 0} or {@code y < 0}
	 */
	public BoardLocation(int x, int y) throws IllegalArgumentException {
		if (x < 0) {
			throw new IllegalArgumentException("x is negative: " + x);
		} else if (y < 0) {
			throw new IllegalArgumentException("y is negative: " + y);
		}
		this.x = x;
		this.y = y;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BoardLocation other = (BoardLocation) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

	/**
	 * Gets the {@code x}-coordinate of this location in the grid.
	 * 
	 * @return the {@code x}-coordinate
	 */
	public int getX() {
		return x;
	}

	/**
	 * Gets the {@code y}-coordinate of this location in the grid.
	 * 
	 * @return the {@code y}-coordinate
	 */
	public int getY() {
		return y;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public String toString() {
		return String.format("(%s, %s)", x, y);
	}

}

@@ -212,16 +212,101 @@
 tion %7B%0A%0A
+%09/**%0A%09 * The side length of the grid.%0A%09 */%0A%09public static final int BOARD_SIZE = 4;%0A%0A
 %09/**%0A%09 *
@@ -378,16 +378,16 @@
 t cells%0A
-
 %09 * in t
@@ -744,16 +744,73 @@
 to zero)
+ and less than the board size%0A%09 * of %7B@value #BOARD_SIZE%7D
 .%0A%09 * %0A%09
@@ -1002,20 +1002,16 @@
 %7B@code x
- %3C 0
 %7D or %7B@c
@@ -1015,20 +1015,94 @@
 %7B@code y
- %3C 0
+%7D is negative, or greater than or%0A%09 *             equal to %7B@value #BOARD_SIZE
 %7D%0A%09 */%0A%09
@@ -1261,32 +1261,32 @@
 se if (y %3C 0) %7B%0A
-
 %09%09%09throw new Ill
@@ -1331,16 +1331,202 @@
 %22 + y);%0A
+%09%09%7D else if (x %3E= BOARD_SIZE) %7B%0A%09%09%09throw new IllegalArgumentException(%22x is too big: %22 + x);%0A%09%09%7D else if (y %3E= BOARD_SIZE) %7B%0A%09%09%09throw new IllegalArgumentException(%22y is too big: %22 + y);%0A
 %09%09%7D%0A%09%09th

Implement maximum board size checking