/// <summary> /// Adds a successor to a list if it is not impassible or the parent node /// </summary> /// <param name="ASuccessors">List of successors</param> /// <param name="AX">X-coordinate</param> /// <param name="AY">Y-coordinate</param> private void AddSuccessor(ArrayList ASuccessors, int AX, int AY) { int CurrentCost = AStarHabbo.GetMap(AX, AY); int CurrentHeight = AStarHabbo.GetHeight(AX, AY); int OldHeight = AStarHabbo.GetHeight(this.X, this.Y); if (CurrentCost == -1) { return; } for (int x = -1; x < 2; x++) { if (CurrentHeight == OldHeight - x) { goto IsReal; } } return; IsReal: AStarNode2D NewNode = new AStarNode2D(this, GoalNode, Cost + CurrentCost, AX, AY); if (NewNode.IsSameState(Parent)) { return; } ASuccessors.Add(NewNode); }
public static AStarNode2D calculateNext(int curx, int cury, int goalx, int goaly, int[,] mapCurrent, int[,] Heightmap) { Map = mapCurrent; Heights = Heightmap; AStar astar = new AStar(); AStarNode2D GoalNode = new AStarNode2D(null, null, 0, goalx, goaly); AStarNode2D StartNode = new AStarNode2D(null, GoalNode, 0, curx, cury); astar.FindPath(StartNode, GoalNode); if (astar.Solution.Count > 1) { AStarNode2D tmpNode = (AStarNode2D)astar.Solution[1]; //tmpNode.Direction = MovementEquations.workDirection(curx, cury, tmpNode.X, tmpNode.Y); return(tmpNode); } else { return(null); } }