import java.io.*;
import java.util.*;

public class Dimension
{
    public Dimension (String dataFile, boolean debug)
    {
        _theWorld = new Vector<ThreeDPoint>();
        _width = 0;
        _height = 0;
        _minZ = 0;
        _maxZ = 0;
        _debug = debug;

        loadLayer(dataFile);
    }

    /**
     * During a cycle, all cubes simultaneously change their state according to the following rules:
     * 
     * If a cube is active and exactly 2 or 3 of its neighbors are also active, the cube remains active.
     * Otherwise, the cube becomes inactive.
     * If a cube is inactive but exactly 3 of its neighbors are active, the cube becomes active.
     * Otherwise, the cube remains inactive.
     */

    public void cycle ()
    {

    }

    @Override
    public String toString ()
    {
        String str = "";

        for (int z = _minZ; z <= _maxZ; z++)
        {
            str += "z="+z+"\n";

            for (int x = 0; x < _width; x++)
            {
                for (int y = 0; y < _height; y++)
                {
                    ThreeDPoint point = new ThreeDPoint(x, y, z);

                    System.out.println("checking "+point);
                    
                    if (_theWorld.contains(point))
                        str += CubeId.ACTIVE;
                    else
                        str += CubeId.INACTIVE;
                }

                str += "\n";
            }
        }

        return str;
    }

    public ThreeDPoint[] neighbours (ThreeDPoint coord)
    {
        int index = 0;

        for (int x = coord.getX() -1; x < coord.getX() +2; x++)
        {
            for (int y = coord.getY() -1; y < coord.getZ() +2; y++)
            {
                for (int z = coord.getZ() -1; z < coord.getZ() +2; z++)
                {
                    ThreeDPoint v = new ThreeDPoint(x, y, z);

                    System.out.println(v);

                    //n[index] = new ThreeDPoint(x, y, z);
                    index++;
                }
            }
        }

        System.out.println("index: "+index);

        return null;
    }

    private void loadLayer (String inputFile)
    {
        BufferedReader reader = null;

        try
        {
            reader = new BufferedReader(new FileReader(inputFile));
            String line = null;

            while ((line = reader.readLine()) != null)
            {
                if (_debug)
                    System.out.println("Loaded line: "+line);

                _width = line.length();

                for (int i = 0; i < line.length(); i++)
                {
                    if (CubeId.ACTIVE == line.charAt(i))
                    {
                        if (_debug)
                            System.out.println("Active cell at "+i+" "+_height);

                        _theWorld.add(new ThreeDPoint(i, _height, 0));
                    }
                    else
                    {
                        if (_debug)
                            System.out.println("Inactive cell at "+i+" "+_height);
                    }
                }

                _height++;
            }
        }
        catch (Throwable ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            try
            {
                reader.close();
            }
            catch (Throwable ex)
            {
            }
        }
    }

    private Vector<ThreeDPoint> _theWorld;
    private int _width;
    private int _height;
    private int _minZ;
    private int _maxZ;
    private boolean _debug;
}
@@ -950,28 +950,29 @@
 int 
-x
+y
  = 0; 
-x
+y
  %3C _
-width; x
+height; y
 ++)%0A
@@ -1010,37 +1010,36 @@
 or (int 
-y
+x
  = 0; 
-y
+x
  %3C _
-height; y
+width; x
 ++)%0A    
@@ -1121,68 +1121,8 @@
  z);
-%0A%0A                    System.out.println(%22checking %22+point);
 %0A   
@@ -1190,16 +1190,100 @@
 point))%0A
+                    %7B%0A                        System.out.println(%22active %22+point);%0A%0A
         
@@ -1312,32 +1312,54 @@
  CubeId.ACTIVE;%0A
+                    %7D%0A
                 
@@ -1359,32 +1359,118 @@
            else%0A
+                    %7B%0A                        System.out.println(%22inactive %22+point);%0A%0A
                 
@@ -1493,32 +1493,54 @@
 ubeId.INACTIVE;%0A
+                    %7D%0A
                 
@@ -2748,32 +2748,101 @@
               %7B%0A
+                    ThreeDPoint p = new ThreeDPoint(i, _height, 0);%0A%0A
                 
@@ -3002,32 +3002,21 @@
  cell at
- %22+i+%22 %22+_height
+: %22+p
 );%0A%0A    
@@ -3053,38 +3053,9 @@
 add(
-new ThreeDPoint(i, _height, 0)
+p
 );%0A 
@@ -3226,24 +3226,13 @@
 l at
- %22+i+%22 %22+_height
+: %22+p
 );%0A 

Update Dimension.java