예제 #1
0
        public string AnalysisInfo(short?infoPlayIndex, ComputerPlayer computerPlayer)
        {
            var gameState = GameState;

            var turn = Turn;

            if (infoPlayIndex != null)
            {
                gameState.PlacePiece((short)infoPlayIndex);
                gameState = gameState.NextTurn();
                turn++;
            }

            var analysisNode = new EvaluationNode(ref gameState, computerPlayer.GetWeights(turn));

            var stringBulider = new StringBuilder();

            stringBulider.AppendLine("\tBlack\tWhite");
            stringBulider.AppendLine("Pieces\t" + BlackAndWhite(analysisNode.PlayerPieces, analysisNode.OpponentPieces, IsBlacksTurn(turn)));
            stringBulider.AppendLine("Mobility\t" + BlackAndWhite(analysisNode.PlayerPlayCount, analysisNode.OpponentPlayCount, IsBlacksTurn(turn)));
            stringBulider.AppendLine("Frontier\t" + BlackAndWhite(analysisNode.PlayerFrontier, analysisNode.OpponentFrontier, IsBlacksTurn(turn)));
            stringBulider.AppendLine("Corner\t" + BlackAndWhite(analysisNode.PlayerCorners, analysisNode.OpponentCorners, IsBlacksTurn(turn)));
            stringBulider.AppendLine("X Square\t" + BlackAndWhite(analysisNode.PlayerXSquares, analysisNode.OpponentXSquares, IsBlacksTurn(turn)));
            stringBulider.AppendLine("C Square\t" + BlackAndWhite(analysisNode.PlayerCSquares, analysisNode.OpponentCSquares, IsBlacksTurn(turn)));
            stringBulider.AppendLine("Edge\t" + BlackAndWhite(analysisNode.PlayerEdges, analysisNode.OpponentEdges, IsBlacksTurn(turn)));
            return(stringBulider.ToString());
        }
예제 #2
0
        public string[] AnalysisInfo(short?infoPlayIndex, ComputerPlayer computerPlayer)
        {
            var gameState = GameState;

            var turn = Turn;

            if (infoPlayIndex != null)
            {
                gameState.PlacePiece((short)infoPlayIndex);
                gameState = gameState.NextTurn();
                turn++;
            }

            var analysisNode = new EvaluationNode(ref gameState, computerPlayer.GetWeights(turn));

            var results = new string[2];

            results[0] = StringSpacing(analysisNode.PlayerPieces)
                         + "\r\n" + StringSpacing(analysisNode.PlayerPlayCount)
                         + "\r\n" + StringSpacing(analysisNode.PlayerFrontier)
                         + "\r\n" + StringSpacing(analysisNode.PlayerCorners)
                         + "\r\n" + StringSpacing(analysisNode.PlayerXSquares)
                         + "\r\n" + StringSpacing(analysisNode.PlayerCSquares)
                         + "\r\n" + StringSpacing(analysisNode.PlayerEdges);

            results[1] = StringSpacing(analysisNode.OpponentPieces)
                         + "\r\n" + StringSpacing(analysisNode.OpponentPlayCount)
                         + "\r\n" + StringSpacing(analysisNode.OpponentFrontier)
                         + "\r\n" + StringSpacing(analysisNode.OpponentCorners)
                         + "\r\n" + StringSpacing(analysisNode.OpponentXSquares)
                         + "\r\n" + StringSpacing(analysisNode.OpponentCSquares)
                         + "\r\n" + StringSpacing(analysisNode.OpponentEdges);

            return(results);
        }
예제 #3
0
 private void ValidateNode(EvaluationNode gameStateNode)
 {
     Assert.IsTrue(gameStateNode.Pieces >= 0 && gameStateNode.Pieces <= 1);
     Assert.IsTrue(gameStateNode.Mobility >= 0 && gameStateNode.Mobility <= 1);
     Assert.IsTrue(gameStateNode.Parity >= 0 && gameStateNode.Parity <= 1);
     Assert.IsTrue(gameStateNode.Pattern >= 0 && gameStateNode.Pattern <= 1);
 }
예제 #4
0
 public double evaluate(EvaluationNode node)
 {
     if (node == null)
     {
         return(0);
     }
     else if (node.getNodeType() == EvaluationNodeType.NUMBER)
     {
         NumberNode numberNode = (NumberNode)node;
         return(numberNode.evaluate());
     }
     else if (node.getNodeType() == EvaluationNodeType.VARIABLE)
     {
         VariableNode variableNode = (VariableNode)node;
         return(variableNode.evaluate(x));
     }
     else if (node.getNodeType() == EvaluationNodeType.FUNCTION)
     {
         FunctionNode functionNode = (FunctionNode)node;
         return(functionNode.evaluate(x));
     }
     else
     {
         OperatorNode operatorNode = (OperatorNode)node;
         double       a            = evaluate(node.left);
         double       b            = evaluate(node.right);
         return(operatorNode.evaluate(a, b));
     }
 }
예제 #5
0
        public void TestMethod1()
        {
            var gameManager   = new GameManager();
            var gameStateNode = new EvaluationNode(ref gameManager.GameState, _weights);

            ValidateNode(gameStateNode);
        }
예제 #6
0
        private FunctionNode readFunctionNode(SemanticNode node)
        {
            Function       function       = getFunction(node.left);
            EvaluationNode parameterRoot  = build(node.right);
            EvaluationTree evaluationTree = new EvaluationTree(parameterRoot);

            return(new FunctionNode(function, evaluationTree));
        }
예제 #7
0
        public override void Interpret(SymbolTable table, FunctionTable functionTable)
        {
            var  _evaluation = EvaluationNode.Evaluate(table);
            bool _result     = InterpreterCase(CaseBlockNode, EvaluationNode, table, functionTable, "case");

            if (!_result)
            {
                _result = InterpreterCase(CaseBlockNode, EvaluationNode, table, functionTable, "defauld");
            }
        }
예제 #8
0
        public void NegaScoutReversiGame2Test()
        {
            var computerPlayer = new ComputerPlayer {
                Search = SearchAlgorithms.NegaScout
            };

            var node = new EvaluationNode(ref _game3.GameState, _weights);

            var score = computerPlayer.Search(node, new SearchConfig(0, 0, 10));

            Assert.AreEqual(0, score);
        }
예제 #9
0
 public override void Interpret(SymbolTable table, FunctionTable functionTable)
 {
     if (EvaluationNode.Evaluate(table))
     {
         foreach (var statementNode in IfCode)
         {
             statementNode.Interpret(table, functionTable);
         }
     }
     else
     {
         IfNotCode.Interpret(table, functionTable);
     }
 }
예제 #10
0
        public void AlphaBetaReversiTest()
        {
            new DepthFirstSearch();

            var computerPlayer = new ComputerPlayer {
                Search = SearchAlgorithms.AlphaBetaNegaMax
            };

            var node = new EvaluationNode(ref _game1.GameState, _weights);

            var score = computerPlayer.Search(node, new SearchConfig(0, 0, 3));

            Assert.AreEqual(1, score);
        }
예제 #11
0
 public override void Interpret(SymbolTable table, FunctionTable functionTable)
 {
     while (EvaluationNode.Evaluate(table))
     {
         try
         {
             foreach (var statementNode in CodeNode)
             {
                 statementNode.Interpret(table, functionTable);
             }
         }
         catch (BreakException)
         {
             return;
         }
         catch (ContinueException)
         {
         }
     }
 }
예제 #12
0
        public void FullGameTest()
        {
            var gameManager = new GameManager();

            while (!gameManager.GameState.IsGameOver)
            {
                if (!gameManager.HasPlays)
                {
                    gameManager.NextTurn();
                    continue;
                }

                var depthFirstSearch  = new DepthFirstSearch();
                var computerPlayIndex = depthFirstSearch.GetPlay(gameManager, new ComputerPlayer());

                gameManager.PlacePiece(computerPlayIndex);
                gameManager.NextTurn();

                var gameStateNode = new EvaluationNode(ref gameManager.GameState, _weights);
                ValidateNode(gameStateNode);
            }
        }
예제 #13
0
 public EvaluationTree(EvaluationNode root)
 {
     this.root = root;
 }
예제 #14
0
 public EvaluationTree(SemanticTree semanticTree)
 {
     this.treeBuilder = new EvaluationTreeBuilder(semanticTree);
     this.root        = treeBuilder.build();
 }