Пример #1
0
        public static double CalculateProbability(GameTreeEvaluationNode <GameState, GameAction, TicTacToeValue> node)
        {
            double crossResult;
            double noughtResult;

            if (node.GameState.CurrentPlayer.IsCross)
            {
                crossResult  = 1;
                noughtResult = 0;
            }
            else
            {
                crossResult  = 0;
                noughtResult = 1;
            }

            switch (node.Evaluation.Max)
            {
            case FieldState.Cross:
                return(crossResult);

            case FieldState.Nought:
                return(noughtResult);

            default:
                return(0);
            }
        }
Пример #2
0
 public static TicTacToePVNetworkOutput Create(GameTreeEvaluationNode <GameState, GameAction, TicTacToeValue> evaluation)
 {
     double[] values = new double[OutputSize];
     TicTacToeActionProbabilities.CalculateProbabilities(values, evaluation);
     values[9] = TicTacToeActionProbabilities.CalculateProbability(evaluation);
     return(new TicTacToePVNetworkOutput(values));
 }
Пример #3
0
        public GameTreeEvaluationNode <GameState, GameAction, LabeledState <GameState, TicTacToeValue> > Evaluate(GameTreeNode <GameState, GameAction> node)
        {
            uint outputSize = node.State.BoardSize * node.State.BoardSize;
            var  result     = new GameTreeEvaluationNode <GameState, GameAction, LabeledState <GameState, TicTacToeValue> >(node.State);

            if (node.State.IsFinal)
            {
                result.Evaluation = EvaluateLeaf(node.State);
            }
            else
            {
                result.Children = new Dictionary <GameAction, GameTreeEvaluationNode <GameState, GameAction, LabeledState <GameState, TicTacToeValue> > >();

                foreach (var child in node.Children)
                {
                    result.Children.Add(child.Key, Evaluate(child.Value));
                }

                result.Evaluation = EvaluateNode(node.State, result.Children.Select(c => c.Value.Evaluation));

                //var allowedActions = Game.GetAllowedActions(node.GameState);
                //int playerIndex = node.GameState.CurrentPlayer.IsCross ? 1 : 0;
                //
                //if (allowedActions.Any())
                //{
                //    result.Children = new Dictionary<GameAction, GameTreeEvaluationNode<GameState, GameAction, TEvaluation>>();
                //
                //    foreach (var allowedAction in allowedActions)
                //    {
                //        var nextGameState = node.GameState.Play(allowedAction.X, allowedAction.Y);
                //        result.Children.Add(allowedAction, Evaluate(nextGameState));
                //    }
                //
                //    //result.Evaluation = EvaluateNode(gameState, result.Children);
                //
                //}
            }

            return(result);
        }
Пример #4
0
        public static void CalculateProbabilities(double[] probabilities, GameTreeEvaluationNode <GameState, GameAction, TicTacToeValue> node)
        {
            for (int i = 0; i < probabilities.Length; i++)
            {
                probabilities[i] = 0;
            }

            double crossResult;
            double noughtResult;

            if (node.GameState.CurrentPlayer.IsCross)
            {
                crossResult  = 1;
                noughtResult = 0;
            }
            else
            {
                crossResult  = 0;
                noughtResult = 1;
            }

            foreach (var child in node.Children)
            {
                double p = 0.5;

                switch (child.Value.Evaluation.Max)
                {
                case FieldState.Cross:
                    p = crossResult;
                    break;

                case FieldState.Nought:
                    p = noughtResult;
                    break;
                }

                probabilities[child.Key.X + child.Key.Y * 3] = p;
            }
        }
Пример #5
0
 public TicTacToeActionProbabilities(GameTreeEvaluationNode <GameState, GameAction, TicTacToeValue> evaluation)
 {
     Probabilities = new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
     CalculateProbabilities(Probabilities, evaluation);
 }