public override PlayerTask GetMove(POGame poGame)
        {
            var player    = poGame.CurrentPlayer;
            var opponent  = poGame.CurrentOpponent;
            var validOpts = poGame.Simulate(player.Options()).Where(x => x.Value != null);
            var history   = opponent.PlayHistory;

            if (player.MulliganState == Mulligan.INPUT)
            {
                List <int> mulligan = new MyScore().MulliganRule().Invoke(player.Choice.Choices.Select(p => poGame.getGame().IdEntityDic[p]).ToList());
                return(ChooseTask.Mulligan(player, mulligan));
            }
            updateProbabilities();

            ActionEstimator = new ActionEstimator(DecksDict, ProbabilitiesDict);

            int optionsCount = validOpts.Count();

            Console.WriteLine("Valid options for TestAgent: ");
            validOpts.ToList().ForEach(option => Console.WriteLine(option));

            var action = validOpts.Any() ?
                         validOpts.Select(option => Score(option, poGame.CurrentPlayer.PlayerId, (optionsCount >= 5) ? ((optionsCount >= 25) ? 1 : 2) : 3)).OrderBy(pair => pair.Value).Last().Key :
                         player.Options().First(option => option.PlayerTaskType == PlayerTaskType.END_TURN);

            Console.WriteLine("TestAgent: " + action);
            return(action);

            void updateProbabilities()
            {
                /* ----------- Counting probabilities ------------ */
                foreach (KeyValuePair <string, List <Card> > deck in DecksDict)
                {
                    int similarCount      = 0;
                    var playedCards       = history.Select(h => h.SourceCard).ToList();
                    var deckCards         = deck.Value;
                    var deckCardsDistinct = deckCards.Distinct().ToList();

                    playedCards
                    .ForEach(playedCard =>
                    {
                        deckCardsDistinct.ForEach(deckCard =>
                        {
                            if (playedCard.Name == deckCard.Name)
                            {
                                similarCount++;
                            }
                        });
                    });

                    double probability = Math.Round((double)similarCount / deckCards.Count(), 2);
                    ProbabilitiesDict[deck.Key] = probability;
                    //if (probability > 0) Console.WriteLine(deck.Key + " has probability of " + ProbabilitiesDict[deck.Key] * 100 + "%");
                }
            }
        }
Exemplo n.º 2
0
 public MCTS(POGame poGame, Dictionary <string, List <Card> > decksDict, Dictionary <string, double> probsDict,
             int turnDepth = 1, int timeBudget = 2000, SelectionStrategy selectionStrategy = SelectionStrategy.UCT,
             StateRateStrategy stateRateStrategy = StateRateStrategy.Greedy, double explorationConstant = 0.5)
 {
     TurnDepth            = turnDepth;
     COMPUTATIONAL_BUDGET = timeBudget;
     EXPLORATION_CONSTANT = explorationConstant;
     Selection            = selectionStrategy;
     StateRate            = stateRateStrategy;
     player       = poGame.CurrentPlayer;
     Root         = new Node(poGame, player.PlayerId);
     InitialState = poGame;
     InitializeNode(Root, InitialState);
     DecksDict         = decksDict;
     ProbabilitiesDict = probsDict;
     ActionEstimator   = new ActionEstimator(DecksDict, ProbabilitiesDict);
     //poGame.CurrentPlayer.Options().ForEach(task => Console.Write(task + " "));
     //Console.WriteLine();
 }