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); } }); }
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)); }
private void ClearGrid() { nodeGrid.Children.Clear(); star = null; end = null; robotGrid = null; nodeLabels.Clear(); }
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; } }
public static int CalculateHeruisticFromNode(this Node node, IRobotGrid grid) { grid.CalculateHeruisticFromNode(node); return(node.Hn); }
public static IEnumerable <Node> FindNeighbours(this Node node, IRobotGrid grid) => grid.FindNeighbours(node);
public static Node SelectNextNode(this Node currentNode, IRobotGrid grid) => grid.SelectNextNode(currentNode);
public static int CalculateGnFromNode(this Node node, Node currentNode, IRobotGrid grid) { grid.CalculateGnFromNode(node, currentNode); return(node.Gn); }