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 y = 0; y < _height; y++)
            {
                for (int x = 0; x < _width; x++)
                {
                    ThreeDPoint point = new ThreeDPoint(x, y, z);
                    
                    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++)
                {
                    ThreeDPoint p = new ThreeDPoint(i, _height, 0);

                    if (CubeId.ACTIVE == line.charAt(i))
                    {
                        if (_debug)
                            System.out.println("Active cell at: "+p);

                        _theWorld.add(p);
                    }
                    else
                    {
                        if (_debug)
                            System.out.println("Inactive cell at: "+p);
                    }
                }

                _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;
}
@@ -57,16 +57,68 @@
 nsion%0A%7B%0A
+    public static final int TOTAL_NEIGHBOURS = 27;%0A%0A
     publ
@@ -1550,66 +1550,101 @@
  0;%0A
-%0A        for (int x = coord.getX() -1; x %3C coord.getX() +2
+        ThreeDPoint%5B%5D n = new ThreeDPoint%5BTOTAL_NEIGHBOURS%5D;%0A%0A        for (int x = -1; x %3C= 1
 ; x+
@@ -1685,44 +1685,18 @@
 y = 
-coord.getY() -1; y %3C coord.getZ() +2
+-1; y %3C= 1
 ; y+
@@ -1745,44 +1745,18 @@
 z = 
-coord.getZ() -1; z %3C coord.getZ() +2
+-1; z %3C= 1
 ; z+
@@ -1824,30 +1824,74 @@
 ThreeDPoint(
-x, y, 
+coord.getX() + x, coord.getY() + y, coord.getZ() +
 z);%0A%0A       
@@ -1951,10 +1951,8 @@
     
-//
 n%5Bin
@@ -1962,32 +1962,9 @@
 %5D = 
-new ThreeDPoint(x, y, z)
+v
 ;%0A  
@@ -2037,54 +2037,8 @@
  %7D%0A%0A
-        System.out.println(%22index: %22+index);%0A%0A
     
@@ -2049,19 +2049,16 @@
 return n
-ull
 ;%0A    %7D%0A

Update Dimension.java