public GraphNode(Location3 location, SurfaceType surface, int speed, Direction direction)
 {
     Location    = location;
     SurfaceType = surface;
     Speed       = speed;
     Direction   = direction;
 }
 public IEnumerable <GraphNode> GetNodes(Location3 location)
 {
     if (!_nodes.TryGetValue(location, out var lst))
     {
         yield break;
     }
     foreach (var n in lst)
     {
         yield return(n);
     }
 }
        public Graph(IEnumerable <MapCell> cells, Location3 start, Location3 finish)
        {
            FinishLocation = finish;
            // Populate cells
            var allDirections = Enum.GetValues(typeof(Direction)).Cast <Direction>().ToList();


            foreach (var cell in cells)
            {
                var lst = new List <GraphNode>();
                void AddAllDirections(Location3 loc, SurfaceType surface, int speed)
                {
                    foreach (var d in allDirections)
                    {
                        lst.Add(new GraphNode(loc, surface, speed, d));
                    }
                }

                if (cell.SurfaceType == SurfaceType.Rock)
                {
                    AddAllDirections(cell.Location, cell.SurfaceType, Speeds.Zero);
                }
                if (cell.SurfaceType == SurfaceType.DangerousArea)
                {
                    AddAllDirections(cell.Location, cell.SurfaceType, Speeds.Hills);
                }
                if (cell.SurfaceType == SurfaceType.Empty)
                {
                    AddAllDirections(cell.Location, cell.SurfaceType, Speeds.Jumper);
                    AddAllDirections(cell.Location, cell.SurfaceType, Speeds.Hills);
                    // We start at zero speed
                    if (cell.Location == start)
                    {
                        AddAllDirections(cell.Location, cell.SurfaceType, Speeds.Zero);
                    }
                }

                if (cell.SurfaceType == SurfaceType.Pit)
                {
                    AddAllDirections(cell.Location, cell.SurfaceType, Speeds.Pits);
                }

                _nodes[cell.Location] = lst;
            }
            foreach (var lst in _nodes.Values)
            {
                foreach (var n in lst)
                {
                    BuildNodeNeighbours(n);
                }
            }
        }
Beispiel #4
0
 public Direction GetDirection(Location3 other) => OffsetDirections[other - this];
Beispiel #5
0
 public int Distance(Location3 other) =>
 (Math.Abs(X - other.X) + Math.Abs(Y - other.Y) + Math.Abs(Z - other.Z)) / 2;
Beispiel #6
0
 public bool Equals(Location3 other)
 {
     return(X == other.X && Y == other.Y && Z == other.Z);
 }