Пример #1
0
        public float GetProbability(SimPlayerTurnContext context, Card card, HashSet <Card> cardsNotInDeck, ICollection <Card> cards)
        {
            float value = 0;

            for (int play = 0; play < NumberOfPlayouts; ++play)
            {
                var currentContext = context.DeepClone();

                this.Cards = new List <Card>(cards);
                var currentDeck = new SimDeck(cardsNotInDeck, currentContext.TrumpCard);

                var firstAction  = (currentContext.FirstPlayedCard != null) ? SimPlayerAction.PlayCard(currentContext.FirstPlayedCard) : null;
                var secondAction = (card == null) ? SimPlayerAction.CloseGame() : SimPlayerAction.PlayCard(card);

                var playAction = (card == null) ? this.CloseGame() : this.PlayCard(card);

                var firstPlayer = new SimDummyPlayer();

                var opponentCardsNumber = (currentContext.FirstPlayedCard == null) ? this.Cards.Count + 1 : this.Cards.Count;

                for (int i = 0; i < opponentCardsNumber; i++)
                {
                    if (currentDeck.CardsLeft == 0)
                    {
                        break;
                    }

                    firstPlayer.AddCard(currentDeck.GetNextCard());
                }

                var stateManager = new SimStateManager();
                stateManager.SetState(currentContext.State);
                var round = new SimRound(firstPlayer, this, GameRulesProvider.Santase, currentDeck, stateManager);


                var result = round.PlaySimulation(
                    currentContext.FirstPlayerRoundPoints,
                    currentContext.SecondPlayerRoundPoints,
                    firstAction,
                    secondAction,
                    firstPlayer.Cards,
                    this.Cards);

                value += this.Expand(result);
            }

            value = value / NumberOfPlayouts;

            return(value);
        }
Пример #2
0
        public float GetProbability(SimPlayerTurnContext context, Card card, HashSet<Card> cardsNotInDeck, ICollection<Card> cards)
        {
            float value = 0;
            for (int play = 0; play < NumberOfPlayouts; ++play)
            {
                var currentContext = context.DeepClone();

                this.Cards = new List<Card>(cards);
                var currentDeck = new SimDeck(cardsNotInDeck, currentContext.TrumpCard);

                var firstAction = (currentContext.FirstPlayedCard != null) ? SimPlayerAction.PlayCard(currentContext.FirstPlayedCard) : null;
                var secondAction = (card == null) ? SimPlayerAction.CloseGame() : SimPlayerAction.PlayCard(card);

                var playAction = (card == null) ? this.CloseGame() : this.PlayCard(card);

                var firstPlayer = new SimDummyPlayer();

                var opponentCardsNumber = (currentContext.FirstPlayedCard == null) ? this.Cards.Count + 1 : this.Cards.Count;

                for (int i = 0; i < opponentCardsNumber; i++)
                {
                    if (currentDeck.CardsLeft == 0)
                    {
                        break;
                    }

                    firstPlayer.AddCard(currentDeck.GetNextCard());
                }

                var stateManager = new SimStateManager();
                stateManager.SetState(currentContext.State);
                var round = new SimRound(firstPlayer, this, GameRulesProvider.Santase, currentDeck, stateManager);

                var result = round.PlaySimulation(
                                                    currentContext.FirstPlayerRoundPoints,
                                                    currentContext.SecondPlayerRoundPoints,
                                                    firstAction,
                                                    secondAction,
                                                    firstPlayer.Cards,
                                                    this.Cards);

                value += this.Expand(result);
            }

            value = value / NumberOfPlayouts;

            return value;
        }
Пример #3
0
        private static SimPlayerTurnContext GetCurrentContext(PlayerTurnContext context)
        {
            SimPlayerTurnContext currentContext = null;

            var stateManager = new SimStateManager();

            if (context.State.GetType().Name == "StartRoundState")
            {
                var state = new SimStartRoundState(stateManager);

                currentContext = new SimPlayerTurnContext(state, context.TrumpCard, context.CardsLeftInDeck, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);
            }
            else if (context.State.GetType().Name == "TwoCardsLeftRoundState")
            {
                var state = new SimTwoCardsLeftRoundState(stateManager);

                currentContext = new SimPlayerTurnContext(state, context.TrumpCard, context.CardsLeftInDeck, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);
            }
            else if (context.State.GetType().Name == "MoreThanTwoCardsLeftRoundState")
            {
                var state = new SimMoreThanTwoCardsLeftRoundState(stateManager);

                currentContext = new SimPlayerTurnContext(state, context.TrumpCard, context.CardsLeftInDeck, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);
            }
            else if (context.State.GetType().Name == "FinalRoundState")
            {
                var state = new SimFinalRoundState(stateManager);

                currentContext = new SimPlayerTurnContext(state, context.TrumpCard, context.CardsLeftInDeck, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);
            }

            currentContext.FirstPlayedCard     = context.FirstPlayedCard;
            currentContext.SecondPlayedCard    = context.SecondPlayedCard;
            currentContext.FirstPlayerAnnounce = context.FirstPlayerAnnounce;

            return(currentContext);
        }
Пример #4
0
        private static SimPlayerTurnContext GetCurrentContext(PlayerTurnContext context)
        {
            SimPlayerTurnContext currentContext = null;

            var stateManager = new SimStateManager();

            if (context.State.GetType().Name == "StartRoundState")
            {
                var state = new SimStartRoundState(stateManager);

                currentContext = new SimPlayerTurnContext(state, context.TrumpCard, context.CardsLeftInDeck, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);
            }
            else if (context.State.GetType().Name == "TwoCardsLeftRoundState")
            {
                var state = new SimTwoCardsLeftRoundState(stateManager);

                currentContext = new SimPlayerTurnContext(state, context.TrumpCard, context.CardsLeftInDeck, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);
            }
            else if (context.State.GetType().Name == "MoreThanTwoCardsLeftRoundState")
            {
                var state = new SimMoreThanTwoCardsLeftRoundState(stateManager);

                currentContext = new SimPlayerTurnContext(state, context.TrumpCard, context.CardsLeftInDeck, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);
            }
            else if (context.State.GetType().Name == "FinalRoundState")
            {
                var state = new SimFinalRoundState(stateManager);

                currentContext = new SimPlayerTurnContext(state, context.TrumpCard, context.CardsLeftInDeck, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);
            }

            currentContext.FirstPlayedCard = context.FirstPlayedCard;
            currentContext.SecondPlayedCard = context.SecondPlayedCard;
            currentContext.FirstPlayerAnnounce = context.FirstPlayerAnnounce;

            return currentContext;
        }