Beispiel #1
0
            //Constructs a board space on top of a provided node argument, obtained from the nodegrid
            //as well as a boardpiece, if placing boardpieces is required at instantiation
            public BoardSpace(BoardNode nodeArg, BoardPiece pieceArg)
            {
                mBoardNode = nodeArg;

                PieceAt           = pieceArg;
                mPiecePresentBool = true;
            }
        /*
         * public int ComputeH(SpaceCoordinate startArg, SpaceCoordinate targetArg)
         * {
         *  return (Math.Abs(targetArg.RowCoordinate - startArg.RowCoordinate) + Math.Abs(targetArg.ColCoordinate - startArg.ColCoordinate));
         * }
         */

        /*
         * Open List
         * Closed List
         * Add the start node to Open
         * loop
         *  current = node in OPEN wiht the lowest f_cost
         *  remove current form Open
         *  add current to Closed
         */
        public Queue <BoardNode> FindPath(BoardNode startArg, BoardNode endArg)
        {
            mOpenList.Add(startArg);
            BoardNode currentNode = startArg;
            bool      pathFound   = false;

            while (!pathFound)
            {
                foreach (BoardNode iNode in mOpenList)
                {
                    if (iNode.FCost < currentNode.FCost)
                    {
                        currentNode = iNode;
                    }
                }
                mOpenList.Remove(currentNode);
                mClosedList.Add(currentNode);
            }
            if (currentNode == endArg)
            {
                //Create Queue and return
            }
            foreach (BoardNode iNeighbor in currentNode.Neighbors)
            {
                if (!iNeighbor.IsWalkable || mClosedList.Contains(iNeighbor))
                {
                    continue;
                }
            }
            return(null);
        }
Beispiel #3
0
        /**
         * Constructor - Instantiate a grid given the bounds to be used, allows for negative bounds
         * Though this isn't really used so may be unnecessary.
         * Note - As this version is not prepared for delivery, it only insantiates a rectangular board in which
         * all nodes are walkable and targetable
         */
        public NodeGrid(int minXCoordArg, int maxXCoordArg, int minYCoordArg, int maxYCoordArg)
        {
            mBoardNodes = new List <BoardNode>();
            for (int i = minXCoordArg; i < maxXCoordArg; i++)
            {
                for (int j = minYCoordArg; j < maxYCoordArg; j++)
                {
                    SpaceCoordinate lCoord     = new SpaceCoordinate(i, j);
                    BoardNode       lBoardNode = new BoardNode(lCoord, true, true);
                    mBoardNodes.Add(lBoardNode);
                }
            }
            mXBounds    = new int[2];
            mXBounds[0] = minXCoordArg;
            mXBounds[1] = maxXCoordArg;

            mYBounds    = new int[2];
            mYBounds[0] = minYCoordArg;
            mYBounds[1] = maxYCoordArg;

            //Instantiate all directions on the node grid, there may be a better place to put these
            //but this allowed me to begin testing other features
            SpaceMovement DIR_UP         = new SpaceMovement(-1, 0, 10);
            SpaceMovement DIR_DOWN       = new SpaceMovement(1, 0, 10);
            SpaceMovement DIR_RIGHT      = new SpaceMovement(0, 1, 10);
            SpaceMovement DIR_LEFT       = new SpaceMovement(0, -1, 10);
            SpaceMovement DIR_UP_RIGHT   = new SpaceMovement(1, 1, 14);
            SpaceMovement DIR_UP_LEFT    = new SpaceMovement(1, -1, 14);
            SpaceMovement DIR_DOWN_RIGHT = new SpaceMovement(-1, 1, 14);
            SpaceMovement DIR_DOWN_LEFT  = new SpaceMovement(-1, -1, 14);

            //Two lists for containing all directions
            mBaseDir = new List <SpaceMovement>();
            mAllDir  = new List <SpaceMovement>();

            //Add the cardinal directions to the base direction list, in clockwise order
            mBaseDir.Add(DIR_UP);
            mBaseDir.Add(DIR_RIGHT);
            mBaseDir.Add(DIR_DOWN);
            mBaseDir.Add(DIR_LEFT);

            //Add all 8 directions to the all direction list, in clockwise order
            mAllDir.Add(DIR_UP);
            mAllDir.Add(DIR_UP_RIGHT);
            mAllDir.Add(DIR_RIGHT);
            mAllDir.Add(DIR_DOWN_RIGHT);
            mAllDir.Add(DIR_DOWN);
            mAllDir.Add(DIR_DOWN_LEFT);
            mAllDir.Add(DIR_LEFT);
            mAllDir.Add(DIR_UP_LEFT);

            //Instatiate each node's neighbor list
            foreach (BoardNode iNode in this.BoardNodes)
            {
                iNode.Neighbors = BoardNode.IdentifyNeighbors(this, iNode.Coordinates);
            }
        }
        //Nodes need to know what their neighbors are for pathfinding to be efficient
        public static List <BoardNode> IdentifyNeighbors(NodeGrid gridArg, SpaceCoordinate coordArg)
        {
            List <BoardNode> lNeighbors = new List <BoardNode>();

            foreach (SpaceMovement iMove in gridArg.ALL_DIRECTIONS)
            {
                SpaceCoordinate possNeighborCoord = coordArg.CoordAtMove(iMove);
                BoardNode       lNode             = gridArg.BoardNodes.Find(x => x.Coordinates.Equals(coordArg));
                if (lNode != null)
                {
                    lNeighbors.Add(lNode);
                }
            }
            return(lNeighbors);
        }
Beispiel #5
0
            //Constructs a board space on top of a provided node argument, obtained from the nodegrid
            public BoardSpace(BoardNode nodeArg)
            {
                mBoardNode = nodeArg;

                mPiecePresentBool = false;
            }