コード例 #1
0
        public void OpenSquare(int y, int x, int[] parent, int moveCost, double heuristic, bool newSquare)
        {
            if (!newSquare)
            {
                foreach (OpenSquare op in OpenList)
                {
                    if (op.Y == y && op.X == x)
                    {
                        newSquare = true;
                        break;
                    }
                }
            }

            if (!newSquare)
            {
                OpenList.Add(new OpenSquare(y, x));
                MapStatus.RemoveAll((c) => c.X == x && c.Y == y);
                MapStatus.Add(new CellInfo(heuristic, null, true, false, x, y));
            }

            CellInfo cell = GetCellInfo(y, x);

            cell.Parent       = parent;
            cell.MovementCost = moveCost;
        }
コード例 #2
0
        public void StartPathfinding(MapPoint startP, MapPoint endP)
        {
            Start  = startP;
            End    = endP;
            StartX = startP.X;
            StartY = startP.Y;
            EndX   = endP.X;
            EndY   = endP.Y;

            StartPoint = new MapPoint(startP.X, startP.Y);
            EndPoint   = new MapPoint(endP.X, endP.Y);

            AuxEndPoint = StartPoint;
            AuxEndX     = StartPoint.X;
            AuxEndY     = StartPoint.Y;

            DistanceToEnd = StartPoint.DistanceToCell(EndPoint);

            for (int y = -19; y <= MaxY; y++)
            {
                for (int x = 0; x <= MaxX; x++)
                {
                    MapStatus.Add(new CellInfo(0, null, false, false, x, y));
                }
            }
            OpenList = new List <OpenSquare>();
            OpenSquare(StartY, StartX, null, 0, 0, false);
        }