예제 #1
0
 public CardHand()
 {
     onTheGame     = false;
     blackJack     = false;
     bust          = false;
     cardValue     = 0;
     softValue     = false;
     isDouble      = false;
     cardsReceived = 0;
     pair          = PairState.None;
 }
예제 #2
0
 internal bool GoalsSatisfied(Pair <Set <CompoundTerm>, Set <Term> > simpleAndFsmGoals, IState state)
 {
     if (typeof(SimpleState) == state.GetType())
     {
         //currently not yet implemented
         return(true);
     }
     else if (typeof(FsmState) == state.GetType())
     {
         FsmState fsmState = (FsmState)state;
         Console.WriteLine("Comparing FsmState: " + state.ToString() + " to " + simpleAndFsmGoals.Second);
         if (fsmState.AutomatonStates.IsSupersetOf(simpleAndFsmGoals.Second))
         {
             return(true);
         }
     }
     else if (typeof(PairState) == state.GetType())
     {
         PairState pairState = (PairState)state;
         return(GoalsSatisfied(simpleAndFsmGoals, pairState.First) && GoalsSatisfied(simpleAndFsmGoals, pairState.Second));
     }
     return(false);
 }
예제 #3
0
        private void countCardValue(Card card, CardHand playerHand, int box)
        {
            string state = "";
            int    value = (int)card.CardRank;

            playerHand.OnTheGame = true;
            //If this is first card for this player,
            //Save this card for pair checking
            if (playerHand.CardsReceived < 1)
            {
                playerHand.FirstCard = card.Clone();
            }
            else if (playerHand.CardsReceived == 1)
            {
                playerHand.SecondCard = card.Clone();
            }

            if (value > 10) //All Picture cards count for value 10
            {
                value = 10;
            }

            //Ace can be value 1 or 11 depend on the total value of the hand;
            if (value == 1 && (playerHand.TotalCardValue + 11) <= 21)
            {
                value = 11;
                playerHand.SoftValue = true;
            }

            playerHand.TotalCardValue += value;
            playerHand.CardsReceived  += 1;

            if (playerHand.TotalCardValue > 21) //if total greater then 21, bust
            {
                playerHand.IsBust    = true;
                playerHand.OnTheGame = false;
            }

            if (playerHand.CardsReceived == 2 && playerHand.TotalCardValue == 21) //first 2 cards 21, this is BlackJack
            {
                if (playerHand.Splited == false)
                {
                    playerHand.IsBlackJack = true;
                }
            }

            // Check the state of the player up to the current card.
            if (playerHand.IsBlackJack == true)
            {
                state = "BJ";
            }
            else if (playerHand.IsBust == true)
            {
                state = "Bust";
            }
            else
            {
                state = playerHand.TotalCardValue.ToString();
            }
            // if this is the second card, check for pair
            if (playerHand.Splited == false)
            {
                if (playerHand.CardsReceived == 2)
                {
                    PairState pairState = checkPair(playerHand.FirstCard, card);
                    if (pairState != PairState.None)
                    {
                        playerHand.Pair = pairState;
                        //state = state + " " + pairState + " Pair";
                    }
                }
            }
            if (box < 5 || box == 10)
            {
                OutPutState(box, state);
            }
            else if (box >= 5 && box < 10)
            {
                if (this.playerHand[box - 5].IsBust)
                {
                    state += " -- " + "BUST";
                }
                else
                {
                    state += " -- " + this.playerHand[box - 5].TotalCardValue;
                }
                OutPutState(box - 5, state);
            }
        }
예제 #4
0
 static IState M2Reduct(PairState productState)
 {
     return productState.Second;
 }
예제 #5
0
 static IState M1Reduct(PairState productState)
 {
     return productState.First;
 }