Esempio n. 1
0
 /// <summary>
 /// Intializes a new mapNode.
 /// </summary>
 /// <param name="X">The X position of this node.</param>
 /// <param name="Y">The Y position of t his node.</param>
 /// <param name="Cost">The cost for the pathfinder to pass this node.</param>
 /// <param name="Parent">The mapNode object of the parent node of this node.</param>
 /// <param name="Goal">The mapNode object of the goal node of this node.</param>
 public mapNode(int X, int Y, double Cost, mapNode Parent, mapNode Goal, mapNode Start)
 {
     this.Parent = Parent;
     this.Start = Start;
     this.Goal = Goal;
     this.X = X;
     this.Y = Y;
     this.Cost = Cost;
 }
Esempio n. 2
0
 /// <summary>
 /// Intializes a new mapNode.
 /// </summary>
 /// <param name="X">The X position of this node.</param>
 /// <param name="Y">The Y position of t his node.</param>
 /// <param name="Cost">The cost for the pathfinder to pass this node.</param>
 /// <param name="Parent">The mapNode object of the parent node of this node.</param>
 /// <param name="Goal">The mapNode object of the goal node of this node.</param>
 public mapNode(int X, int Y, double Cost, mapNode Parent, mapNode Goal, mapNode Start)
 {
     this.Parent = Parent;
     this.Start  = Start;
     this.Goal   = Goal;
     this.X      = X;
     this.Y      = Y;
     this.Cost   = Cost;
 }
Esempio n. 3
0
 internal mapNode(int X, int Y, double Cost, mapNode parentNode, mapNode goalNode, Pathfinder parentPathfinder)
 {
     this.X          = X;
     this.Y          = Y;
     this.parentNode = parentNode;
     this.goalNode   = goalNode;
     _Cost           = Cost;
     _Pathfinder     = parentPathfinder;
     Successors      = new ArrayList();
 }
Esempio n. 4
0
            private void addSuccessor(int X, int Y)
            {
                if (_Pathfinder.spotOpen(X, Y) == false || _Pathfinder.spotMoveHeightOK(this.X, this.Y, X, Y) == false)
                {
                    return;
                }

                mapNode newNode = new mapNode(X, Y, _Cost, this, goalNode, _Pathfinder);

                Successors.Add(newNode);
                return;
            }
Esempio n. 5
0
        public Coord getNext(int X, int Y, int goalX, int goalY)
        {
            if (X == goalX && Y == goalY)
                return new Coord(-1, 0);

            int maxCycles = (maxX * maxY) ^ 2;
            int Cycles = 0;

            ArrayList Solution = new ArrayList();
            this.Goal = new mapNode(goalX, goalY, 0, null, null, null);
            this.Start = new mapNode(X, Y, 0, null, Goal, null);
            Goal.Start = Goal;
            Start.Start = Start;

            Open.Add(Start);
            while (Open.Count > 0)
            {
                if (Cycles >= maxCycles)
                    return new Coord(-1, 0);
                else
                    Cycles++;

                mapNode Current = (mapNode)Open.Pop();
                if (Current.X == Goal.X && Current.Y == Goal.Y)
                {
                    while (Current != null)
                    {
                        Solution.Insert(0, Current);
                        Current = Current.Parent;
                    }
                    break;
                }
                else
                {
                    foreach (mapNode Successor in Current.Successors(this))
                    {
                        mapNode openNode = null;
                        if (Open.Contains(Successor))
                        {
                            openNode = (mapNode)Open[Open.IndexOf(Successor)];
                            if (Successor.totalCost > openNode.totalCost)
                                continue;
                        }

                        mapNode closedNode = null;
                        if (Closed.Contains(Successor))
                        {
                            closedNode = (mapNode)Closed[Closed.IndexOf(Successor)];
                            if (Successor.totalCost > closedNode.totalCost)
                                continue;
                        }

                        Open.Remove(Successor);
                        Closed.Remove(Successor);
                        Open.Push(Successor);
                    }
                    Closed.Add(Current);
                }
            }
            if (Solution.Count == 0)
                return new Coord(-1, 0);
            else
            {
                mapNode Next = (mapNode)Solution[1];
                return new Coord(Next.X, Next.Y);
            }
        }
Esempio n. 6
0
        public dribbelaerPath getPath(int X, int Y, int goalX, int goalY)
        {
            if (X == goalX && Y == goalY)
                return null;

            int maxCycles = (maxX * maxY) ^ 2;
            int Cycles = 0;

            dribbelaerPath Path = new dribbelaerPath();
            this.Goal = new mapNode(goalX, goalY, 0, null, null, null);
            this.Start = new mapNode(X, Y, 0, null, Goal, null);
            Goal.Start = Goal;
            Start.Start = Start;

            Open.Add(Start);
            while (Open.Count > 0)
            {
                if (Cycles >= maxCycles)
                    return null;
                else
                    Cycles++;

                mapNode Current = (mapNode)Open.Pop();
                if (Current.X == Goal.X && Current.Y == Goal.Y)
                {
                    while (Current != null)
                    {
                        Path.Coords.Push(new Coord(Current.X, Current.Y));
                        Current = Current.Parent;
                    }
                    break;
                }
                else
                {
                    foreach (mapNode Successor in Current.Successors(this))
                    {
                        mapNode openNode = null;
                        if (Open.Contains(Successor))
                        {
                            openNode = (mapNode)Open[Open.IndexOf(Successor)];
                            if (Successor.totalCost > openNode.totalCost)
                                continue;
                        }

                        mapNode closedNode = null;
                        if (Closed.Contains(Successor))
                        {
                            closedNode = (mapNode)Closed[Closed.IndexOf(Successor)];
                            if (Successor.totalCost > closedNode.totalCost)
                                continue;
                        }

                        Open.Remove(Successor);
                        Closed.Remove(Successor);
                        Open.Push(Successor);
                    }
                    Closed.Add(Current);
                }
            }
            if (Path.Coords.Count == 0)
                return null;
            else
                return Path;
        }
        public Coord getNext(int X, int Y, int goalX, int goalY)
        {
            if (X == goalX && Y == goalY)
            {
                return(new Coord(-1, 0));
            }

            int maxCycles = (maxX * maxY) ^ 2;
            int Cycles    = 0;

            ArrayList Solution = new ArrayList();

            this.Goal   = new mapNode(goalX, goalY, 0, null, null, null);
            this.Start  = new mapNode(X, Y, 0, null, Goal, null);
            Goal.Start  = Goal;
            Start.Start = Start;

            Open.Add(Start);
            while (Open.Count > 0)
            {
                if (Cycles >= maxCycles)
                {
                    return(new Coord(-1, 0));
                }
                else
                {
                    Cycles++;
                }

                mapNode Current = (mapNode)Open.Pop();
                if (Current.X == Goal.X && Current.Y == Goal.Y)
                {
                    while (Current != null)
                    {
                        Solution.Insert(0, Current);
                        Current = Current.Parent;
                    }
                    break;
                }
                else
                {
                    foreach (mapNode Successor in Current.Successors(this))
                    {
                        mapNode openNode = null;
                        if (Open.Contains(Successor))
                        {
                            openNode = (mapNode)Open[Open.IndexOf(Successor)];
                            if (Successor.totalCost > openNode.totalCost)
                            {
                                continue;
                            }
                        }

                        mapNode closedNode = null;
                        if (Closed.Contains(Successor))
                        {
                            closedNode = (mapNode)Closed[Closed.IndexOf(Successor)];
                            if (Successor.totalCost > closedNode.totalCost)
                            {
                                continue;
                            }
                        }

                        Open.Remove(Successor);
                        Closed.Remove(Successor);
                        Open.Push(Successor);
                    }
                    Closed.Add(Current);
                }
            }
            if (Solution.Count == 0)
            {
                return(new Coord(-1, 0));
            }
            else
            {
                mapNode Next = (mapNode)Solution[1];
                return(new Coord(Next.X, Next.Y));
            }
        }
        public dribbelaerPath getPath(int X, int Y, int goalX, int goalY)
        {
            if (X == goalX && Y == goalY)
            {
                return(null);
            }

            int maxCycles = (maxX * maxY) ^ 2;
            int Cycles    = 0;

            dribbelaerPath Path = new dribbelaerPath();

            this.Goal   = new mapNode(goalX, goalY, 0, null, null, null);
            this.Start  = new mapNode(X, Y, 0, null, Goal, null);
            Goal.Start  = Goal;
            Start.Start = Start;

            Open.Add(Start);
            while (Open.Count > 0)
            {
                if (Cycles >= maxCycles)
                {
                    return(null);
                }
                else
                {
                    Cycles++;
                }

                mapNode Current = (mapNode)Open.Pop();
                if (Current.X == Goal.X && Current.Y == Goal.Y)
                {
                    while (Current != null)
                    {
                        Path.Coords.Push(new Coord(Current.X, Current.Y));
                        Current = Current.Parent;
                    }
                    break;
                }
                else
                {
                    foreach (mapNode Successor in Current.Successors(this))
                    {
                        mapNode openNode = null;
                        if (Open.Contains(Successor))
                        {
                            openNode = (mapNode)Open[Open.IndexOf(Successor)];
                            if (Successor.totalCost > openNode.totalCost)
                            {
                                continue;
                            }
                        }

                        mapNode closedNode = null;
                        if (Closed.Contains(Successor))
                        {
                            closedNode = (mapNode)Closed[Closed.IndexOf(Successor)];
                            if (Successor.totalCost > closedNode.totalCost)
                            {
                                continue;
                            }
                        }

                        Open.Remove(Successor);
                        Closed.Remove(Successor);
                        Open.Push(Successor);
                    }
                    Closed.Add(Current);
                }
            }
            if (Path.Coords.Count == 0)
            {
                return(null);
            }
            else
            {
                return(Path);
            }
        }
Esempio n. 9
0
        public int[] getNext(int X, int Y, int goalX, int goalY)
        {
            if (X == goalX && Y == goalY)
            {
                return(null);
            }

            int maxCycles = (maxX * maxY);
            int Cycles    = 0;

            goalNode  = new mapNode(goalX, goalY, 0, null, null, this);
            startNode = new mapNode(X, Y, 0, null, goalNode, this);

            openList.Add(startNode);

            while (openList.Count > 0)
            {
                if (Cycles == maxCycles)
                {
                    return(null);
                }
                Cycles++;

                mapNode curNode = (mapNode)openList.Pop();
                if (curNode.sameCoordsAs(goalNode))
                {
                    while (curNode != null)
                    {
                        solutionList.Insert(0, curNode);
                        curNode = curNode.parentNode;
                    }
                    break;
                }
                else
                {
                    curNode.getSuccessors();
                    successorList = curNode.allSuccessors;
                    foreach (mapNode Node in successorList)
                    {
                        mapNode nodeOpen = null;
                        if (openList.Contains(Node))
                        {
                            nodeOpen = (mapNode)openList[openList.IndexOf(Node)];
                            if (Node.totalCost > nodeOpen.totalCost)
                            {
                                continue;
                            }
                        }

                        mapNode nodeClosed = null;
                        if (closedList.Contains(Node))
                        {
                            nodeClosed = (mapNode)closedList[closedList.IndexOf(Node)];
                            if (Node.totalCost > nodeClosed.totalCost)
                            {
                                continue;
                            }
                        }

                        openList.Remove(nodeOpen);
                        closedList.Remove(nodeClosed);
                        openList.Push(Node);
                    }
                    closedList.Add(curNode);
                }
            }
            if (solutionList.Count == 0)
            {
                return(null);
            }

            mapNode solutionNode = (mapNode)solutionList[1];

            int[] Next = new int[2];
            Next[0] = solutionNode.X;
            Next[1] = solutionNode.Y;

            return(Next);
        }
Esempio n. 10
0
 internal bool sameCoordsAs(mapNode Node)
 {
     return(X == Node.X && Y == Node.Y);
 }