private static void CheckBox(Level level, Array2D<int> noBoxMap, Array2D<bool> simpleDeadlockMap, Coordinate2D coord) { // Check whether we've visited this square before. if (noBoxMap[coord] == 0) { return; } // This square is not a no-box square. noBoxMap[coord] = 0; // Recursively check for other squares that are not no-box squares. foreach (Direction direction in Direction.Directions) { // Get parallel and perpendicular offsets. Coordinate2D parallel = direction; Coordinate2D perpendicular = Coordinate2D.Transpose(parallel); // Check whether we can move the box to the new position. if (level.IsFloor(coord - parallel) && level.IsFloor(coord + parallel)) { Coordinate2D oldBoxCoord = coord; Coordinate2D newBoxCoord = coord + parallel; // Check for the special case of no influence pushes that lead to deadlocks. bool specialCase = false; while (level.IsWall(oldBoxCoord + perpendicular) && level.IsWall(oldBoxCoord - perpendicular) && ((level.IsWall(newBoxCoord + perpendicular) && level.IsWallOrEmpty(newBoxCoord - perpendicular)) || (level.IsWallOrEmpty(newBoxCoord + perpendicular) && level.IsWall(newBoxCoord - perpendicular)))) { if (level.IsTarget(newBoxCoord)) { break; } if (!level.IsFloor(newBoxCoord) || simpleDeadlockMap[newBoxCoord]) { specialCase = true; break; } oldBoxCoord += parallel; newBoxCoord += parallel; } // Otherwise recursively check for more squares. if (!specialCase) { CheckBox(level, noBoxMap, simpleDeadlockMap, coord + parallel); } } } }