import java.util.*;

/*
 * Instances of this class are used to record the current
 * search pattern through the tunnels. We need to remember
 * the starting point, the keys we've found and the number
 * of steps to this stage.
 */

public class State
{
    public State (State current, Coordinate pos)
    {
        this(current, pos, null);
    }

    public State (State current, Coordinate pos, Character key)
    {
        _coord = pos;
        _keys = new HashSet<Character>(current._keys);

        if (key != null)
            _keys.add(key);

        _steps = current._steps +1;
        _id = Util.keycode(_keys);
    }

    public State (Coordinate coord, Set<Character> keys, int steps)
    {
        _coord = coord;
        _keys = keys;
        _steps = steps;
        _id = Util.keycode(keys);
    }

    public Coordinate getPosition ()
    {
        return _coord;
    }

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

    public int numberOfSteps ()
    {
        return _steps;
    }

    public boolean hasKey (char door)
    {
        char key = Character.toLowerCase(door);

        return _keys.contains(key);
    }

    public Set<Character> getKeys ()
    {
        return _keys;
    }

    @Override
    public int hashCode ()
    {
        return _coord.hashCode();
    }

    @Override
    public boolean equals (Object obj)
    {
        if (obj == null)
            return false;

        if (this == obj)
            return true;
        
        if (getClass() == obj.getClass())
        {
            State temp = (State) obj;

            if (temp._coord.equals(_coord))
            {
                return temp._keys.containsAll(_keys);
            }
        }

        return false;
    }

    @Override
    public String toString ()
    {
        return "State: "+_coord+", "+_id+", "+_steps;
    }

    private Coordinate _coord;
    private Set<Character> _keys;
    private int _steps;
    private String _id;
}

@@ -260,39 +260,24 @@
 blic State (
-State current, 
 Coordinate p
@@ -275,19 +275,21 @@
 rdinate 
-pos
+coord
 )%0A    %7B%0A
@@ -300,31 +300,116 @@
     
-this(current, pos, null
+_coord = coord;%0A        _keys = Collections.emptySet();%0A        _steps = 0;%0A        _id = Util.keycode(_keys
 );%0A 
@@ -473,19 +473,23 @@
 aracter 
-key
+content
 )%0A    %7B%0A
@@ -578,19 +578,23 @@
     if (
-key
+content
  != null
@@ -605,191 +605,158 @@
     
+  %7B%0A
       
-_keys.add(key);%0A%0A        _steps = current._steps +1;%0A        _id = Util.keycode(_keys
+      if (Util.isKey(content))%0A            %7B%0A                System.out.println(%22is key%22
 );%0A
+%0A
     
-%7D%0A%0A
     
-public State (Coordinate coord, Set%3CCharacter%3E keys, int steps)
+        _keys.add(content);
 %0A    
-%7B%0A
         
 _coo
@@ -755,45 +755,20 @@
     
-_coord = coord;%0A        _keys = keys;
+%7D%0A        %7D%0A
 %0A   
@@ -781,21 +781,33 @@
 steps = 
+current._
 steps
+ +1
 ;%0A      
@@ -827,16 +827,17 @@
 keycode(
+_
 keys);%0A 

Update State.java