Esempio n. 1
0
        public static CardGameAI DumbAI()
        {
            CardGameAI result = new CardGameAI();

            result.winProbability = (me, them, isFirst, bidScalar) => 1;
            result.foldProbaility = (me, them, isFirst, bidScalar) => 0;
            return(result);
        }
Esempio n. 2
0
        public static CardGameAI CalculatedAI()
        {
            CardGameAI result = new CardGameAI();

            result.winProbability = (me, them, isFirst, bidScalar) => CardProbability.winProbability[me.visibleScore];
            result.foldProbaility = (me, them, isFirst, bidScalar) => 0;
            return(result);
        }
Esempio n. 3
0
        public static CardGameAI TurnProbability(AllTurnProbabilities probability)
        {
            CardGameAI result = new CardGameAI();

            result.winProbability = (me, them, isFirst, bidScalar) => probability.GetWinProbability(them.cardsPlayed, me.visibleScore, isFirst ? 0 : bidScalar, them.visibleScore, them.allMatch);
            result.foldProbaility = (me, them, isFirst, bidScalar) => probability.GetFoldProbability(them.cardsPlayed, me.cardsPlayed, me.visibleScore, me.initialAllMatch, isFirst ? bidScalar : 0, them.visibleScore, them.allMatch);
            result.learn          = (turnResults, amIFirst, myTopScore, theirTopScore, myDouble, theirDouble) => probability.Learn(turnResults, amIFirst, myTopScore, theirTopScore, myDouble, theirDouble);
            return(result);
        }
Esempio n. 4
0
        private float FinishAITurn(int bid, int bidScalar, CardGameAI ai)
        {
            currentBid       = bid;
            currentBidScalar = bidScalar;
            amountInPot     += currentBid;
            AdvanceTurn();

            TurnResult subResult = CaclulateOptimalTurn(ai);

            return(subResult.value - bid);
        }
Esempio n. 5
0
        private float TakeOtherPlayerTurn(float foldProb, int bid, int bidScalar, CardGameAI ai)
        {
            // other player responds
            CardGameState nextState = Clone();

            nextState.currentBid       = bid;
            nextState.currentBidScalar = bidScalar;
            nextState.amountInPot     += bid;
            nextState.AdvanceTurn();

            TurnResult subResult = nextState.CaclulateOptimalTurn(ai);

            return(subResult.value * (1 - foldProb) + amountInPot * foldProb);
        }
Esempio n. 6
0
        private TurnResult TakeAITurn(int bid, int bidScalar, CardGameAI ai)
        {
            TurnResult result = shootout.TurnResult.Fold();


            aiPlayer.ForEachInHand((index) =>
            {
                CardGameState nextState = Clone();

                Card cardPlayed = nextState.aiPlayer.PlayCard(index);

                if (round == 2 && nextState.aiPlayer.CanPlayTriple())
                {
                    nextState.aiPlayer.ForEachInHand((fourthIndex) =>
                    {
                        CardGameState fourthPlayState = nextState.Clone();

                        Card fourthCard = fourthPlayState.aiPlayer.PlayFourthCard(fourthIndex);

                        float score = fourthPlayState.FinishAITurn(bid, bidScalar, ai);

                        if (score > result.value)
                        {
                            result.value      = score;
                            result.chosenCard = cardPlayed;
                            result.bid        = nextState.currentBid;
                            result.fourthCard = fourthCard;
                        }
                    });
                }
                else
                {
                    float score = nextState.FinishAITurn(bid, bidScalar, ai);

                    if (score > result.value)
                    {
                        result.value      = score;
                        result.chosenCard = cardPlayed;
                        result.bid        = nextState.currentBid;
                    }
                }
            });

            return(result);
        }
Esempio n. 7
0
        public TurnResult CaclulateOptimalTurn(CardGameAI ai)
        {
            TurnResult result = TurnResult.Fold();

            if (round == 3)
            {
                ++checkCount;
                result.value = ai.winProbability(aiPlayer, otherPlayer, isAIFirst, currentBidScalar) * amountInPot;
            }
            else
            {
                int minBid   = (amountInPot - currentBid) / 2;
                int cardSlot = aiPlayer.cardsPlayed;

                if (isFirstTurn && isAIFirst)
                {
                    // this player goes first
                    for (int bidScalar = 1; bidScalar <= 3; ++bidScalar)
                    {
                        TurnResult subResult = TakeAITurn(bidScalar * minBid, bidScalar, ai);

                        if (subResult.value > result.value)
                        {
                            result = subResult;
                        }
                    }
                }
                else if (!isFirstTurn && isAIFirst)
                {
                    // other player responds
                    float foldProb = ai.foldProbaility(aiPlayer, otherPlayer, isAIFirst, currentBidScalar);
                    result.value = TakeOtherPlayerTurn(foldProb, currentBid, currentBidScalar, ai);
                }
                else if (!isFirstTurn && !isAIFirst)
                {
                    // this player responds
                    result = TakeAITurn(currentBid, currentBidScalar, ai);
                }
                else
                {
                    // other player goes first
                    float foldProb = ai.foldProbaility(aiPlayer, otherPlayer, isAIFirst, currentBidScalar);

                    float scoreResult = float.PositiveInfinity;

                    for (int bidScalar = 1; bidScalar <= 3; ++bidScalar)
                    {
                        float singleResult = TakeOtherPlayerTurn(foldProb, bidScalar * minBid, bidScalar, ai);

                        if (singleResult < scoreResult)
                        {
                            scoreResult = singleResult;
                        }
                    }

                    result.value = scoreResult;
                }
            }

            return(result);
        }
Esempio n. 8
0
 public CalculatedAI(int index, PlayerHand hand, Text moneyLabel, shootout.CardGameAI ai)
     : base(index, hand, moneyLabel)
 {
     this.ai = ai;
 }