public static int SolutionChanges(Level level, MoveList solution) { if (solution == null) { return -1; } Level tempLevel = new Level(level); int changes = 0; int lastBoxIndex = -1; foreach (OperationDirectionPair pair in solution) { if (pair.Operation == Operation.Push) { int boxIndex = tempLevel.BoxIndex(tempLevel.SokobanCoordinate + pair.Direction); if (boxIndex != lastBoxIndex) { changes++; lastBoxIndex = boxIndex; } } tempLevel.Move(pair); } return changes; }
public static int MinimumBoxMoves(Level level, MoveList solution) { if (solution == null) { return -1; } int boxes = level.Boxes; if (boxes == 0) { return 0; } int[] boxMoves = new int[boxes]; Level tempLevel = new Level(level); foreach (OperationDirectionPair pair in solution) { if (pair.Operation == Operation.Push) { boxMoves[tempLevel.BoxIndex(tempLevel.SokobanCoordinate + pair.Direction)]++; } tempLevel.Move(pair); } int min = int.MaxValue; foreach (int moves in boxMoves) { min = Math.Min(min, moves); } return min; }