public static Stack <List <int> > GetFillingSteps(INavigator navigator, LocationGroup locationGroup) { var result = new Stack <List <int> >(); var antiNavigator = navigator.ReplaceWithBoxes(locationGroup); var scope = new Queue <INavigator>(); scope.Enqueue(antiNavigator); while (scope.Count > 0) { var currentNavigator = scope.Dequeue(); var step = new List <int>(); foreach (var entryPoint in locationGroup.EntryPoints) { var boxesToExit = GetBoxesToExit(currentNavigator, entryPoint); step.AddRange(boxesToExit.Except(step)); } if (step.Count > 0) { var navigatorAfterStep = currentNavigator.Replace(step, Sokoban.LOCATION); scope.Enqueue(navigatorAfterStep); result.Push(step); } } return(result); }
public INavigator ReplaceWithBoxes(LocationGroup group) { var newMap = map.Replace(Sokoban.BOX, Sokoban.EMPTY) .Replace(Sokoban.BOX_ON_LOCATION, Sokoban.LOCATION) .Replace(Sokoban.KEEPER, Sokoban.EMPTY) .Replace(Sokoban.KEEPER_ON_LOCATION, Sokoban.LOCATION); var sb = new StringBuilder(newMap); foreach (var location in group.Positions) { sb[location] = Sokoban.BOX_ON_LOCATION; } sb[group.EntryPoints[0].Position] = Sokoban.KEEPER; return(new Navigator(Width, Height, sb.ToString())); }