if (item.getValue() >= 0 && item.getValue() < keyRooms.size())
keyRooms.set(item.getValue(), room);
}
// for N >= 0: keyRooms[N] = location of key N
Room current = dungeon.findStart(),
goal = dungeon.findGoal();
// Clients may disable generation of the goal room -- the equivalent
// 'ending' room becomes the boss room.
if (goal == null) goal = dungeon.findBoss();
assert current != null && goal != null;
int nextKey = 0, nonlinearity = 0;
Set<Integer> visitedRooms = new TreeSet<Integer>();
while (current != goal) {
Room intermediateGoal;
if (nextKey == constraints.getMaxKeys())
intermediateGoal = goal;
else
intermediateGoal = keyRooms.get(nextKey);