import java.util.*;

/**
 * A map of the tunnel system.
 */

public class Map
{
    public Map (Vector<String> input, boolean debug)
    {
        _theMap = new Vector<Cell>();
        _debug = debug;

        createMap(input);
    }

    public Coordinate getEntrance ()
    {
        Enumeration<Cell> iter = _theMap.elements();

        while (iter.hasMoreElements())
        {
            Cell theCell = iter.nextElement();

            if (theCell.isEntrance())
                return theCell.position();
        }

        return null;  // oops!! shouldn't happen.
    }

    @Override
    public String toString ()
    {
        Enumeration<Cell> iter = _theMap.elements();
        int index = 1;
        String str = "Map <"+(_maxX+1)+", "+(_maxY+1)+">:\n\n";

        while (iter.hasMoreElements())
        {
            str += iter.nextElement().getContents();

            if (index++ == _maxX)
            {
                str += "\n";

                index = 1;
            }
        }

        return str;
    }

    // create the map from input
    
    private void createMap (Vector<String> input)
    {
        Enumeration<String> iter = input.elements();
        int y = -1;

        _maxX = input.get(0).length(); // all lines are the same length

        while (iter.hasMoreElements())
        {
            y++;

            String line = iter.nextElement();

            for (int x = 0; x < _maxX; x++)
            {
                Cell theCell = new Cell(new Coordinate(x, y), line.charAt(x), _debug);

                if (theCell.isEntrance())
                    _entrance = theCell.position();  // should be only one!

                if (_debug)
                    System.out.println(theCell);

                _theMap.add(theCell);
            }
        }

        _maxY = y;
    }

    // from the map create a graph

    public void createGraph ()  // temporary public for testing!
    {
        Node[][] nodeMap = new Node[_maxX][_maxY];
        Enumeration<Cell> iter = _theMap.elements();



        
        Vector<Node> graph = new Vector<Node>();
        
        while (iter.hasMoreElements())
        {
            Cell c = iter.nextElement();

            Coordinate coord = c.position();
            Coordinate up = getUpPosition(coord);
            Coordinate down = getDownPosition(coord);
            Coordinate left = getLeftPosition(coord);
            Coordinate right = getRightPosition(coord);

            /*
             * Check to see if the Node is already part.
             */

            int upIndex = graph.indexOf(new Node(up));
            Node upNode = ((upIndex == -1) ? null : allNodes.elementAt(upIndex));

            int downIndex = allNodes.indexOf(new Node(down));
            Node downNode = ((downIndex == -1) ? null : allNodes.elementAt(downIndex));

            int leftIndex = allNodes.indexOf(new Node(left));
            Node leftNode = ((leftIndex == -1) ? null : allNodes.elementAt(leftIndex));

            int rightIndex = allNodes.indexOf(new Node(right));
            Node rightNode = ((rightIndex == -1) ? null : allNodes.elementAt(rightIndex));

            Node theNode = new Node(n.getCell(), upNode, downNode, leftNode, rightNode);

            graph.add(theNode);
        }
    }

    private Coordinate getUpPosition (Coordinate coord)
    {
        Coordinate pos = new Coordinate(coord.getX(), coord.getY() +1);

        if (pos.getY() < _maxY)
            return pos;
        else
            return null;
    }

    private Coordinate getDownPosition (Coordinate coord)
    {
        Coordinate pos = new Coordinate(coord.getX(), coord.getY() -1);

        if (pos.getX() >= 0)
            return pos;
        else
            return null;
    }

    private Coordinate getLeftPosition (Coordinate coord)
    {
        Coordinate pos = new Coordinate(coord.getX() -1, coord.getY());

        if (pos.getX() >= 0)
            return pos;
        else
            return null;
    }

    private Coordinate getRightPosition (Coordinate coord)
    {
        Coordinate pos = new Coordinate(coord.getX() +1, coord.getY());

        if (pos.getY() < _maxX)
            return pos;
        else
            return null;
    }

    private Vector<Cell> _theMap;
    private int _maxX;
    private int _maxY;
    private Coordinate _entrance;
    private boolean _debug;
}
@@ -2024,19 +2024,16 @@
 ();%0A
-%0A%0A%0A
         
 %0A   
@@ -2032,66 +2032,38 @@
     
-%0A        Vector%3CNode%3E graph = new Vector%3CNode%3E();%0A        
+int x = 0;%0A        int y = 0;%0A
 %0A   
@@ -2124,2059 +2124,223 @@
     
-Cell c = iter.nextElement();%0A%0A            Coordinate coord = c.position();%0A            Coordinate up = getUpPosition(coord);%0A            Coordinate down = getDownPosition(coord);%0A            Coordinate left = getLeftPosition(coord);%0A            Coordinate right = getRightPosition(coord);%0A%0A            /*%0A             * Check to see if the Node is already part.%0A             */%0A%0A            int upIndex = graph.indexOf(new Node(up));%0A            Node upNode = ((upIndex == -1) ? null : allNodes.elementAt(upIndex));%0A%0A            int downIndex = allNodes.indexOf(new Node(down));%0A            Node downNode = ((downIndex == -1) ? null : allNodes.elementAt(downIndex));%0A%0A            int leftIndex = allNodes.indexOf(new Node(left));%0A            Node leftNode = ((leftIndex == -1) ? null : allNodes.elementAt(leftIndex));%0A%0A            int rightIndex = allNodes.indexOf(new Node(right));%0A            Node rightNode = ((rightIndex == -1) ? null : allNodes.elementAt(rightIndex));%0A%0A            Node theNode = new Node(n.getCell(), upNode, downNode, leftNode, rightNode);%0A%0A            graph.add(theNode);%0A        %7D%0A    %7D%0A%0A    private Coordinate getUpPosition (Coordinate coord)%0A    %7B%0A        Coordinate pos = new Coordinate(coord.getX(), coord.getY() +1);%0A%0A        if (pos.getY() %3C _maxY)%0A            return pos;%0A        else%0A            return null;%0A    %7D%0A%0A    private Coordinate getDownPosition (Coordinate coord)%0A    %7B%0A        Coordinate pos = new Coordinate(coord.getX(), coord.getY() -1);%0A%0A        if (pos.getX() %3E= 0)%0A            return pos;%0A        else%0A            return null;%0A    %7D%0A%0A    private Coordinate getLeftPosition (Coordinate coord)%0A    %7B%0A        Coordinate pos = new Coordinate(coord.getX() -1, coord.getY());%0A%0A        if (pos.getX() %3E= 0)%0A            return pos;%0A        else%0A            return null;%0A    %7D%0A%0A    private Coordinate getRightPosition (Coordinate coord)%0A    %7B%0A        Coordinate pos = new Coordinate(coord.getX() +1, coord.getY());%0A%0A        if (pos.getY() %3C _maxX)%0A            return pos;%0A        else%0A            return null;
+nodeMap%5Bx%5D%5By%5D = new Node(iter.nextElement());%0A%0A            x++;%0A            y++;%0A%0A            if (x == _maxX)%0A                x = 0;%0A%0A            if (y == _maxY)%0A                y = 0;%0A        %7D%0A%0A%0A        %0A        %7D
 %0A   

Update Map.java