public PathResult Compute(MapLocation origin, MapLocation destination) { List <MapLocation> path = new List <MapLocation>(); List <MapLocation> safeLocations = new List <MapLocation>(); List <MapLocation> unsafeLocations = new List <MapLocation>(); path = new List <MapLocation> { origin }; MapLocation currentLocation = origin; while (currentLocation != destination) { var directionOfMovement = currentLocation.GetDirectionTo(destination); var closestSafeLocation = new MapDirection(); var nextPosition = currentLocation.Move(directionOfMovement, 1); var nextPositionTile = _map.GetTile(nextPosition); if (nextPositionTile.IsObstacle) { unsafeLocations.Add(nextPosition); if (directionOfMovement == MapDirection.East || directionOfMovement == MapDirection.West) { closestSafeLocation = FindEastWestClosestSafeLocation(nextPosition, closestSafeLocation); nextPosition = currentLocation.Move(closestSafeLocation, 1); } if (directionOfMovement == MapDirection.North || directionOfMovement == MapDirection.South) { closestSafeLocation = FindNorthSouthClosestSafeLocation(nextPosition, closestSafeLocation); nextPosition = currentLocation.Move(closestSafeLocation, 1); } } else { safeLocations.Add(nextPosition); } currentLocation = nextPosition; //var tile = _map.GetTile(currentLocation); //var template = tile.Template; //_map.SetTile(currentLocation, new MapTileTemplate(template), true); path.Add(nextPosition); //var nextPositionTile = _map.GetTile(nextPosition); //if (nextPositionTile.IsObstacle) //{ // var directionMoved = //} } path.Add(destination); var pathFound = false; return(new PathResult(pathFound, path, safeLocations)); }