コード例 #1
0
ファイル: WayPoint.cs プロジェクト: dvdking/PeoplePolder
 public WayPoint(Point Position, WayPoint Parent, bool type)
 {
     this.PositionX = Position.X;
     this.PositionY = Position.Y;
     this.Parent = Parent;
     this.type = type;
 }
コード例 #2
0
ファイル: BinaryHeap.cs プロジェクト: dvdking/PeoplePolder
        public void Add(WayPoint point)
        {
            Count++;
            Array.Resize<WayPoint>(ref List, Count + 1);
            List[Count] = point;
            int CurrentIndex = Count;
            int parentIndex = CurrentIndex / 2;

            while (CurrentIndex != 1)
            {
                parentIndex = CurrentIndex / 2;
                if (List[parentIndex] == null)
                {
                    WayPoint tmpValue = this.List[parentIndex];
                    this.List[parentIndex] = this.List[CurrentIndex];
                    this.List[CurrentIndex] = tmpValue;
                    CurrentIndex = parentIndex;
                }
                else if (this.List[CurrentIndex].Cost <= List[parentIndex].Cost)
                {
                    WayPoint tmpValue = this.List[parentIndex];
                    this.List[parentIndex] = this.List[CurrentIndex];
                    this.List[CurrentIndex] = tmpValue;
                    CurrentIndex = parentIndex;
                }
                else
                {
                    break;
                }
            }
        }
コード例 #3
0
ファイル: AStar.cs プロジェクト: dvdking/PeoplePolder
        public List<Vector2> FoundCellWay(Point startCell, Point endCell)
        {
            pointMap = new byte[StrategyManager.GameField.Width, StrategyManager.GameField.Height];
            OpenList = new BinaryHeap();

            WayPoint startPoint = new WayPoint(startCell, null, true);
            startPoint.CalculateCost(Creature, endCell, ImprovedPathFinding);

            OpenList.Add(startPoint);

            while (OpenList.Count != 0)
            {
                WayPoint node = OpenList.Get();
                if (node.PositionX == endCell.X && node.PositionY == endCell.Y)
                {
                    WayPoint nodeCurrent = node;
                    List<Vector2> points = new List<Vector2>();

                    while (nodeCurrent != null)
                    {
                        points.Insert(0, new Vector2(nodeCurrent.PositionX, nodeCurrent.PositionY));
                        nodeCurrent = nodeCurrent.Parent;
                    }
                    return points;
                }

                OpenList.Remove();
                Point temp = new Point(node.PositionX, node.PositionY);
                if (DiagonalMovesAllowed)
                {
                    if (CheckPassability(temp.X - 1, temp.Y) && CheckPassability(temp.X, temp.Y - 1))
                        AddNode(node, -1, -1, false, endCell);
                    if (CheckPassability(temp.X + 1, temp.Y) && CheckPassability(temp.X, temp.Y - 1))
                        AddNode(node, 1, -1, false, endCell);
                    if (CheckPassability(temp.X - 1, temp.Y) && CheckPassability(temp.X, temp.Y + 1))
                        AddNode(node, -1, 1, false, endCell);
                    if (CheckPassability(temp.X + 1, temp.Y) && CheckPassability(temp.X, temp.Y + 1))
                        AddNode(node, 1, 1, false, endCell);
                }

                AddNode(node, -1, 0, true, endCell);
                AddNode(node, 0, -1, true, endCell);
                AddNode(node, 1, 0, true, endCell);
                AddNode(node, 0, 1, true, endCell);
            }
            return null;
        }
コード例 #4
0
ファイル: AStar.cs プロジェクト: dvdking/PeoplePolder
        private void AddNode(WayPoint node, sbyte offSetX, sbyte offSetY, bool type, Point endCell)
        {
            Point pos = new Point(node.PositionX + offSetX, node.PositionY + offSetY);

            if (!CheckPassability(pos.X, pos.Y))
                return;
            if(!StrategyManager.GameField.InRange(pos.X, pos.Y))
                return;
            if (pointMap[pos.X, pos.Y] != 1)
            {
                WayPoint temp = new WayPoint(pos, node, type);
                temp.CalculateCost(Creature, endCell, ImprovedPathFinding);
                OpenList.Add(temp);
                pointMap[pos.X, pos.Y] = 1;
            }
        }