예제 #1
0
        // Generates all the piece selections that could possibly be made for a given gamestate.
        public static void generateChildrenPiece(Node currentNode, Node parentNode, int maxDepth, int depth)
        {
            int pieceMapCount = 0;
            int childCount    = 0;

            while (pieceMapCount < MAXGAMEBOARD)
            {
                if (currentNode.pieces[pieceMapCount].getPlayablePiece())
                {
                    totalGamestates++;
                    Node nextNode = new Node();

                    for (int counter = 0; counter < MAXGAMEBOARD; counter++)
                    {
                        string value = currentNode.gameBoard[counter];
                        nextNode.gameBoard[counter] = value;
                    }

                    nextNode.pieceToPlay = pieceMapCount;
                    int newMove = currentNode.moveOnBoard;

                    nextNode.moveOnBoard = newMove;
                    nextNode.parent      = parentNode;

                    parentNode.children[childCount] = nextNode;

                    AIFunctions.copyPieceMap(nextNode, currentNode, pieceMapCount);

                    childCount++;
                    if (depth < maxDepth)
                    {
                        Node childNode      = nextNode;
                        Node nextParentNode = childNode;
                        int  piece          = nextNode.pieceToPlay;
                        int  newDepth       = depth + 1;
                        generateChildrenGamestate(childNode, nextParentNode, piece, maxDepth, newDepth);
                    }
                }
                pieceMapCount++;
            }
        }
예제 #2
0
        // Generates all the moves that could possibly be made for a given gamestate and piece.
        public static void generateChildrenGamestate(Node currentNode, Node parentNode, int piece, int maxDepth, int depth)
        {
            int boardPosCount = 0;
            int childCount    = 0;

            while (boardPosCount < MAXGAMEBOARD)
            {
                if (currentNode.gameBoard[boardPosCount] == null)
                {
                    Node nextNode = new Node();
                    for (int counter = 0; counter < MAXGAMEBOARD; counter++)
                    {
                        string value = currentNode.gameBoard[counter];
                        nextNode.gameBoard[counter] = value;
                    }
                    nextNode.gameBoard[boardPosCount] = currentNode.pieces[piece].getPiece();

                    nextNode.moveOnBoard = boardPosCount;

                    nextNode.parent = parentNode;
                    parentNode.children[childCount] = nextNode;

                    AIFunctions.copyPieceMap(nextNode, currentNode, piece);
                    nextNode.pieceToPlay = NULLPIECE;

                    childCount++;
                    if (depth < maxDepth)
                    {
                        Node childNode      = nextNode;
                        Node nextParentNode = childNode;
                        int  newDepth       = depth + 1;
                        generateChildrenPiece(childNode, nextParentNode, maxDepth, newDepth);
                    }
                }
                boardPosCount++;
            }
        }