Ejemplo n.º 1
0
        private static BackpropagationContainer defaultPolicy(IMctsableGameState gameState)
        {
            IMctsableGameState gameForSimulation = gameState.duplicate();

            Random rng = new Random();

            List <IMove> pathToResult = new List <IMove>(), possibleMoves;
            IMove        chosenMove;

            while (!gameForSimulation.isGameOver())
            {
                possibleMoves = gameForSimulation.getPossibleMoves();

                chosenMove = possibleMoves[rng.Next(possibleMoves.Count)];

                gameForSimulation.makeMove(chosenMove);
                pathToResult.Add(chosenMove);
            }

            return(new BackpropagationContainer(gameForSimulation.getResultOfTheGame(), pathToResult));
        }
Ejemplo n.º 2
0
        private static BackpropagationContainer mctsSearch(IMctsableGameState gameState, MctsNode node)
        {
            if (!node.areChildNodesExpanded)
            {
                if (node.playouts == 0)
                {
                    return(defaultPolicy(gameState));
                }

                node.expandNode();
            }

            MctsNode bestNode = MctsNode.childSelection(node, _DEFAULT_EXPLORATION_CONSTANT);

            gameState.makeMove(bestNode.move);

            BackpropagationContainer result;

            if (!gameState.isGameOver())
            {
                result = mctsSearch(gameState, bestNode);
            }
            else
            {
                result = new BackpropagationContainer(gameState.getResultOfTheGame(), null);
            }

            bestNode.addResult(result.gameResult);
            bestNode.addResultToAMAFChilds(result);

            if (result.pathToResult != null)
            {
                result.addMoveToPath(bestNode.move);
            }

            return(result);
        }