예제 #1
0
 public IEnumerable<Path> FindPath(Position start, decimal distance)
 {
     var newPath = new Path(start);
     var resultDict = new Dictionary<Position, Path> {{newPath.EndPosition, newPath}};
     FindPaths(new Path(start), distance, resultDict);
     return resultDict.Values.Where(x => x.Distance > 0).OrderBy(x => x.Distance);
 }
예제 #2
0
        private void FindPaths(Path path, decimal distance, Dictionary<Position,Path> coveredPositions)
        {
            var adjacentSpaces = path.GetPathsToAdjacentSpaces();
            var inRangeAdjacentSpaces = adjacentSpaces
                .Where(x => x.Distance <= distance)
                .Where(x => _allowsMovement.IsAllowedPosition(x.EndPosition))
                .ToList();

            var validAdjacentSpaces = new List<Path>();
            foreach (var inRangeAdjacentSpace in inRangeAdjacentSpaces)
            {
                if (coveredPositions.ContainsKey(inRangeAdjacentSpace.EndPosition))
                {
                    if (coveredPositions[inRangeAdjacentSpace.EndPosition].Distance > inRangeAdjacentSpace.Distance)
                    {
                        coveredPositions[inRangeAdjacentSpace.EndPosition] = inRangeAdjacentSpace;
                        validAdjacentSpaces.Add(inRangeAdjacentSpace);
                    }
                }
                else
                {
                    coveredPositions.Add(inRangeAdjacentSpace.EndPosition,inRangeAdjacentSpace);
                    validAdjacentSpaces.Add(inRangeAdjacentSpace);
                }
            }

            validAdjacentSpaces.ForEach(x => FindPaths(x,distance,coveredPositions));
        }
예제 #3
0
파일: Path.cs 프로젝트: BrianZell/MapTools
 private Path(Path source, Position position, decimal distance)
 {
     this.StartPosition = source.StartPosition;
     this.EndPosition = position;
     this.Distance = source.Distance + distance;
     this._pathPositions.AddRange(source._pathPositions.Concat(new [] {position}));
 }