コード例 #1
0
ファイル: Node.cs プロジェクト: dzole92/VerojatnostnaRobotika
        public void SetNeighbours(List <Node> neighbours, IRobotGrid grid)
        {
            neighbours.ForEach(x => {
                if (x.Parent == null && x.IsInitialized && !x.Equals(grid.StartNode))
                {
                    x.CalculateGnFromNode(this, grid);
                    x.CalculateHeruisticFromNode(grid);
                    x.SetParent(this);
                }
                else
                {
                    var oldGn = x.Gn;
                    if (x.CalculateGnFromNode(this, grid) < oldGn)
                    {
                        x.SetParent(this);
                    }
                    else
                    {
                        x.Gn = oldGn;
                    }
                }

                if (!Neighbours.Contains(x, new NodeComparer()))
                {
                    Neighbours.Add(x);
                }
            });
        }
コード例 #2
0
 public static MoveType CalculateMoveType(this Node currentNode, Node node, IRobotGrid grid)
 {
     return((MoveType)Enum.Parse(typeof(MoveType),
                                 currentNode.NeighboursIndexes(grid.SizeX, grid.SizeY)
                                 .First(x => x.X == node.Position.X && x.Y == node.Position.Y)
                                 .AdditionalData));
 }
コード例 #3
0
 private void ClearGrid()
 {
     nodeGrid.Children.Clear();
     star      = null;
     end       = null;
     robotGrid = null;
     nodeLabels.Clear();
 }
コード例 #4
0
        private void GenerateNodeGrid()
        {
            ClearGrid();
            if (sizeX == 0 || sizeY == 0)
            {
                throw new Exception("Grid size is not initialized.");
            }
            var nodePosition = new NodePosition {
                X = -450, Y = -350, AdditionalData = "LabelPosition"
            };

            robotGrid = new RobotGrid(sizeX, sizeY, horizontalCost, verticalCost, diagonalCost);

            for (int i = 0; i < sizeY; i++)
            {
                for (int j = 0; j < sizeX; j++)
                {
                    CreateNode(robotGrid.AllNodes.GetValue(i, j) as Node, nodePosition);
                    nodePosition.X += 55;
                }
                nodePosition.X  = -450;
                nodePosition.Y += 55;
            }
        }
コード例 #5
0
 public static int CalculateHeruisticFromNode(this Node node, IRobotGrid grid)
 {
     grid.CalculateHeruisticFromNode(node);
     return(node.Hn);
 }
コード例 #6
0
 public static IEnumerable <Node> FindNeighbours(this Node node, IRobotGrid grid) => grid.FindNeighbours(node);
コード例 #7
0
 public static Node SelectNextNode(this Node currentNode, IRobotGrid grid) => grid.SelectNextNode(currentNode);
コード例 #8
0
 public static int CalculateGnFromNode(this Node node, Node currentNode, IRobotGrid grid)
 {
     grid.CalculateGnFromNode(node, currentNode);
     return(node.Gn);
 }