private int pathLengthFromLocation(int x, int y,
			AStarPathFinder pathfinder, Map toPlay) {
		Path path = pathfinder.findPath(null, x, y,
				toPlay.getWidthInTiles() - 1, 0);

		if (path != null) {
			return path.getLength();
		}

		Tile closestKey = null;
		int shortestLength = Integer.MAX_VALUE;

		for (Tile key : toPlay.getKeys()) {
			path = pathfinder.findPath(null, x, y, key.x, key.y);

			if (path != null) {
				int length = path.getLength();
				if (length < shortestLength) {
					closestKey = key;
					shortestLength = length;
				}
			}
		}

		if (closestKey != null) {
			toPlay.keyPressed(closestKey.x, closestKey.y);
			int fromHere = 	pathLengthFromLocation(closestKey.x, closestKey.y,
					pathfinder, toPlay);		
			if(fromHere == 0)
				return 0;
			
			return shortestLength + fromHere;
		}
		
		return 0;

	}