package pylos.model;

/**
 * Represent an (immutable) position on the Board.
 * x and y are horizontal coordinates, z is the level in the pyramid.
 */
public class Position {
	public static final Position[][][] positions = new Position[Model.LEVELS][][];
	public static Position top;
	public final int x, y, z;

	private Position(int x, int y, int z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}

	@Override
	public String toString() {
		return "(" + x + ", " + y + ", " + z + ")";
	}

	public static void createPositions() {
		for (int level = 0; level < Model.LEVELS; level++) {
			positions[level] = new Position[Model.LEVELS - level][Model.LEVELS - level];
			for (int y = 0; y < Model.LEVELS - level; y++) {
				for (int x = 0; x < Model.LEVELS - level; x++) {
					positions[level][y][x] = new Position(x, y, level);
				}
			}
		}
		top = Position.at(0, 0, Model.LEVELS - 1);
	}

	public static Position at(int x, int y, int z) {
		return positions[z][y][x];
	}

	// No equals(), Positions are unique and can be compared by identity
}

@@ -248,16 +248,81 @@
 S%5D%5B%5D%5B%5D;%0A
+%09public static final Position%5B%5D all = new Position%5BModel.BALLS%5D;%0A
 %09public 
@@ -342,16 +342,16 @@
 on top;%0A
-
 %09public 
@@ -586,16 +586,53 @@
 ons() %7B%0A
+%09%09int all_index = 0;%0A%09%09Position pos;%0A
 %09%09for (i
@@ -875,27 +875,8 @@
 %09pos
-itions%5Blevel%5D%5By%5D%5Bx%5D
  = n
@@ -899,16 +899,80 @@
 , level)
+;%0A%09%09%09%09%09positions%5Blevel%5D%5By%5D%5Bx%5D = pos;%0A%09%09%09%09%09all%5Ball_index++%5D = pos
 ;%0A%09%09%09%09%7D%0A

add a uni-dimensional array to easily access all Positions