import java.util.*;

/**
 * A map of the tunnel system. Assume the data
 * has already had the single entrance converted
 * to 4 in this part. If not we'll need to do that
 * convrsion on the fly (TO DO).
 * 
 * Split into 4 Maps and work each robot until it
 * has to wait for another, then swap between them?
 */

public class Map
{
    public Map (Vector<String> input, boolean debug)
    {
        _theMap = new Vector<Cell>();
        _entrances = new Vector<Coordinate>();
        _locationsOfKeys = new Vector<Coordinate>();
        _keys = new Vector<Character>();
        _doors = new Vector<Character>();
        _debug = debug;

        createMap(input);

        if (_entrances.size() == 1)
            transformEntrance();
    }

    public Vector<Coordinate> getEntrances ()
    {
        return _entrances;
    }

    public Vector<Coordinate> getKeyLocations ()
    {
        return _locationsOfKeys;
    }

    /**
     * Return the content of the Cell represented by the Coordinate.
     */

    public char getContent (Coordinate coord)
    {
        int index = _theMap.indexOf(new Cell(coord));
        Cell theCell = _theMap.get(index);

        return theCell.getContents(); // assume no error
    }

    /*
     * Is this Coordinate in range and can be moved into?
     */

    public boolean validPosition (Coordinate coord)
    {
        if ((coord.getX() >= 0) && (coord.getY() >= 0))
        {
            if ((coord.getX() < _maxX) && (coord.getY() < _maxY))
            {
                int index = _theMap.indexOf(new Cell(coord));

                if (index != -1) {
                    Cell theCell = _theMap.get(index);

                    if (theCell != null)
                        return !theCell.isWall();
                }
            }
        }

        return false;
    }

    public int numberOfKeys ()
    {
        return _keys.size();
    }

    public int numberOfDoors ()
    {
        return _doors.size();
    }

    @Override
    public String toString ()
    {
        Enumeration<Cell> iter = _theMap.elements();
        int index = 1;
        String str = "Map <" + _maxX + ", " + _maxY + ">:\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 (check?)

        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));

                if (theCell.isEntrance())
                    _entrances.add(theCell.position());
                else
                {
                    if (theCell.isKey())
                    {
                        _locationsOfKeys.add(theCell.position());
                        _keys.add(theCell.getContents());
                    }
                    else
                    {
                        if (theCell.isDoor())
                            _doors.add(theCell.getContents());
                    }
                }

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

                _theMap.add(theCell);
            }
        }

        _maxY = y + 1;
    }

    /*
     * Transform the single entrace ...
     * 
     * ...
     * .@.
     * ...
     * 
     * to ...
     * 
     * @#@
     * ###
     * @#@
     */

    private void transformEntrance ()
    {

    }

    private Vector<Cell> _theMap;
    private int _maxX;
    private int _maxY;
    private Vector<Coordinate> _entrances;
    private Vector<Coordinate> _locationsOfKeys;
    private Vector<Character> _keys;
    private Vector<Character> _doors;
    private boolean _debug;
}
@@ -3827,16 +3827,1060 @@
 )%0A    %7B%0A
+        Cell%5B%5D theCells = new Cell%5B9%5D;%0A        int index = 0;%0A        Coordinate theEntrance = _entrances.get(0);  // assume only one!%0A%0A        for (int x = -1; x %3C 2; x++)%0A        %7B%0A            for (int y = -1; y %3C 2; y++)%0A            %7B%0A                Cell tempCell = new Cell(new Coordinate(theEntrance.getX() + x, theEntrance.getY() + y));%0A                int contains = _theMap.indexOf(tempCell);%0A%0A                if (contains != -1)%0A                %7B%0A                    theCells%5Bindex%5D = _theMap.get(contains);%0A                    theCells%5Bindex%5D.setContents(CellId.STONE_WALL);%0A                %7D%0A                else%0A                    theCells%5Bindex%5D = null;%0A            %7D%0A        %7D%0A%0A        if (theCells%5B0%5D != null)%0A            theCells%5B0%5D.setContents(CellId.ENTRANCE);%0A%0A        if (theCells%5B2%5D != null)%0A            theCells%5B2%5D.setContents(CellId.ENTRANCE);%0A%0A        if (theCells%5B6%5D != null)%0A            theCells%5B6%5D.setContents(CellId.ENTRANCE);%0A%0A        if (theCells%5B8%5D != null)%0A            theCells%5B8%5D.setContents(CellId.ENTRANCE);
 %0A    %7D%0A%0A

Update Map.java