public Scenario(int box, SokobanPathItem ep) { Box = box; EntryPoint = ep; PathToEntryPoint = new List <SokobanPathItem>(); BoxesOnTheWayToEntryPoint = new List <int>(); }
public SokobanPathItem GetPathItem(Position from, Position to) { var pathItem = new SokobanPathItem(); pathItem.Position = Convert(from); var dx = from.X - to.X; var dy = from.Y - to.Y; if (dx == 0) { pathItem.StepsToTarget = Math.Abs(dy); pathItem.Key = (dy < 0) ? Key.Down : Key.Up; } else { pathItem.StepsToTarget = Math.Abs(dx); pathItem.Key = (dx < 0) ? Key.Right : Key.Left; } return(pathItem); }
public void FindPathToEntryPoint(SokobanMap virtualMap) { PathToEntryPoint.Clear(); var boxPathFinder = new BoxPathFinder(virtualMap); var path = boxPathFinder.FindPath(virtualMap.Convert(Box), virtualMap.Convert(EntryPoint.Position)); SokobanPathItem currentItem = null; for (int i = 0; i < path.Length - 1; i++) { var item = virtualMap.GetPathItem(path[i], path[i + 1]); if (currentItem == null || currentItem.Key != item.Key) { currentItem = item; PathToEntryPoint.Add(currentItem); } else if (currentItem.Key == item.Key) { currentItem.StepsToTarget++; } } }