예제 #1
0
 private static Card GetBestMoveOfType(CardType type, List <Card> availableMoves, CardType trumpType, Deck deck)
 {
     if (ContainsCards(new Card[] { new Card(CardValue.ACE, type), new Card(CardValue.KING, type), new Card(CardValue.QUEEN, type) }, availableMoves))
     {
         //  HAS ACE, KING, QUEEN = PLAY QUEEN
         return(availableMoves.GetCard(type, CardValue.QUEEN));
     }
     else if (ContainsCards(new Card[] { new Card(CardValue.ACE, type), new Card(CardValue.KING, type) }, availableMoves))
     {
         //  HAS ACE, KING = PLAY KING
         return(availableMoves.GetCard(type, CardValue.KING));
     }
     else if (ContainsCards(new Card[] { new Card(CardValue.QUEEN, type) }, availableMoves) && PlayedCards.HasBeenPlayed(type, CardValue.ACE) && PlayedCards.HasBeenPlayed(type, CardValue.KING) &&
              PlayedCards.NoBodyUsesTrumpTo(type, trumpType))
     {
         //  HAS QUEEN, ACE AND KING HAS BEEN PLAYED AND NOBODY USES TRUMP
         return(availableMoves.GetCard(type, CardValue.KING));
     }
     else if (availableMoves.Contains(type, CardValue.KING) && PlayedCards.HasBeenPlayed(type, CardValue.ACE))
     {
         //  HAS KING, ACE HAS BEEN PLAYED
         return(availableMoves.GetCard(type, CardValue.KING));
     }
     else if (availableMoves.Contains(type, CardValue.ACE) && PlayedCards.PlayedCardCountOfType(type) > 2 && PlayedCards.NoBodyUsesTrumpTo(type, trumpType))
     {
         //  THIS TYPE HAS BEEN USED TWICE, USE THE ACE
         return(availableMoves.GetCard(type, CardValue.ACE));
     }
     else if (availableMoves.Contains(type, CardValue.KING) && !availableMoves.Contains(type, CardValue.ACE) && GetCardsOfType(type, deck).Count > 2)
     {
         //  HAS KING BUT NOT ACE TRY TO GET THEM TO PLAY THE ACE
         Card cardToPlay = availableMoves.GetSomeCardBiggerThan(new Card(CardValue.SEVEN, type));
         if (cardToPlay == null || cardToPlay.GetNumericValue() > 12)
         {
             cardToPlay = availableMoves.GetCardOfType(type);
         }
         return(cardToPlay);
     }
     else
     {
         return(null);
     }
 }
예제 #2
0
        public static Card GetBestMove(Hand currentHand, Deck deck, Player player)
        {
            CardType    trumpType      = currentHand.GetCurrentRoundReference().GetTrumpType();
            bool        firstToPlay    = currentHand.GetInitiater().GetPlayersSeat() == player.GetPlayersSeat();
            bool        trumpUsable    = currentHand.GetCurrentRoundReference().isTrumpUsable();
            List <Card> availableMoves = GetAvailableMoves(currentHand, deck, player);
            List <Card> bestMoves      = new List <Card>();

            if (firstToPlay)
            {
                //  PLAYER INITIATES THE HAND
                bool playTrump     = false;
                Card bestTrumpMove = null;
                if (trumpUsable && (13 - PlayedCards.PlayedCardCountOfType(trumpType)) / 4 < GetCardsOfType(trumpType, deck).Count)
                {
                    //  COLLECT TRUMPS
                    bestTrumpMove = GetBestMoveOfType(trumpType, availableMoves, trumpType, deck);
                    if (bestTrumpMove != null && bestTrumpMove.ToCardString() != String.Empty)
                    {
                        playTrump = true;
                    }
                }
                if (playTrump)
                {
                    return(bestTrumpMove);
                }
                else
                {
                    Card bestMoveDiamond = GetBestMoveOfType(CardType.Diamond, availableMoves, trumpType, deck);
                    if (bestMoveDiamond != null && PlayedCards.NoBodyUsesTrumpTo(CardType.Diamond, trumpType))
                    {
                        bestMoves.Add(bestMoveDiamond);
                    }
                    Card bestMoveSpade = GetBestMoveOfType(CardType.Spade, availableMoves, trumpType, deck);
                    if (bestMoveSpade != null && PlayedCards.NoBodyUsesTrumpTo(CardType.Spade, trumpType))
                    {
                        bestMoves.Add(bestMoveSpade);
                    }
                    Card bestMoveClub = GetBestMoveOfType(CardType.Club, availableMoves, trumpType, deck);
                    if (bestMoveClub != null && PlayedCards.NoBodyUsesTrumpTo(CardType.Club, trumpType))
                    {
                        bestMoves.Add(bestMoveClub);
                    }
                    Card bestMoveHeart = GetBestMoveOfType(CardType.Heart, availableMoves, trumpType, deck);
                    if (bestMoveHeart != null && PlayedCards.NoBodyUsesTrumpTo(CardType.Heart, trumpType))
                    {
                        bestMoves.Add(bestMoveHeart);
                    }

                    if (bestMoves.Count != 0)
                    {
                        bestMoves.Sort(new CardComparer(false));
                        return(bestMoves[bestMoves.Count - 1]);
                    }
                    else
                    {
                        return(availableMoves[0]);
                    }
                }
            }
            else
            {
                //  THIS IS AN ONGOING HAND
                CardType handType = currentHand.GetPlayedCards()[0].GetPlayedCard().GetCardType();
                //  GOING TO USE TRUMP
                if (!deck.ContainsCardOfType(handType))
                {
                    if ((PlayedCards.NoBodyUsesTrumpTo(handType, trumpType) && PlayedCards.PlayedCardCountOfType(handType) < 2) || currentHand.GetPlayedCardCount() == 3)
                    {
                        return(availableMoves[0]);
                    }
                    else if (PlayedCards.PlayedCardCountOfType(handType) > 2)
                    {
                        //  SOMEBODY USES TRUMP
                        Card cardToPlay = availableMoves[0];
                        for (int i = availableMoves.Count - 1; i >= 0; i--)
                        {
                            if (availableMoves[i].GetCardValue() == CardValue.ACE)
                            {
                                //  IF HAS ACE AND DOESNT HAVE KING PLAY IT
                                if (!availableMoves.Contains(new Card(CardValue.KING, trumpType)))
                                {
                                    cardToPlay = availableMoves[i];
                                }
                            }
                            else if (availableMoves[i].GetCardValue() == CardValue.KING && (PlayedCards.HasBeenPlayed(trumpType, CardValue.ACE) || availableMoves.Contains(new Card(CardValue.ACE, trumpType))))
                            {
                                //  HAS ACE OR ACE HAS ALREADY BEEN PLAYED / PLAY THE KING
                                cardToPlay = availableMoves[i];
                            }
                            else if (availableMoves[i].GetCardValue() == CardValue.JOKER && (PlayedCards.HasBeenPlayed(trumpType, CardValue.KING) || availableMoves.Contains(new Card(CardValue.KING, trumpType)) &&
                                                                                             ((PlayedCards.HasBeenPlayed(trumpType, CardValue.ACE) || availableMoves.Contains(new Card(CardValue.ACE, trumpType))))))
                            {
                                //  PLAY THE QUEEN
                                cardToPlay = availableMoves[i];
                            }
                        }
                        return(cardToPlay);
                    }
                    else
                    {
                        return(availableMoves[0]);
                    }
                }
                else
                {
                    //  PLAY THE SAME TYPE OF CARD AS THE HAND
                    if (PlayedCards.NoBodyUsesTrumpTo(handType, trumpType) && currentHand.GetPlayedCardCount() != 3)
                    {
                        //  NOBODY USES TRUMP
                        if (ContainsCards(new Card[] { new Card(CardValue.ACE, handType), new Card(CardValue.KING, handType), new Card(CardValue.QUEEN, handType) }, availableMoves))
                        {
                            //  HAS ACE, KING, QUEEN = PLAY QUEEN
                            return(availableMoves.GetCard(handType, CardValue.QUEEN));
                        }
                        else if (ContainsCards(new Card[] { new Card(CardValue.ACE, handType), new Card(CardValue.KING, handType) }, availableMoves))
                        {
                            //  HAS ACE, KING = PLAY KING
                            return(availableMoves.GetCard(handType, CardValue.KING));
                        }
                        else if (ContainsCards(new Card[] { new Card(CardValue.QUEEN, handType) }, availableMoves) && PlayedCards.HasBeenPlayed(handType, CardValue.ACE) && PlayedCards.HasBeenPlayed(handType, CardValue.KING))
                        {
                            //  HAS QUEEN, ACE AND KING HAS BEEN PLAYED
                            return(availableMoves.GetCard(handType, CardValue.KING));
                        }
                        else
                        {
                            return(availableMoves[0]);
                        }
                    }
                    else
                    {
                        //  SOMEBODY USES TRUMP OR WE ARE THE LAST ONE TO PLAY
                        return(availableMoves[0]);
                    }
                }
            }
        }