Ejemplo n.º 1
0
        private static Card GiveRandomBasedCard(Player player, Deck deck, Card playedFromOther = null)
        {
            var rand = new Random();

            if (playedFromOther != null)
            {
                if ((deck.Cards.Count() == 0 || deck.IsClosed) && SixtySixUtil.HasAnsweringCard(player, playedFromOther))
                {
                    var answeringCards = SixtySixUtil.GetHandAnsweringCards(player, playedFromOther);
                    return(answeringCards[rand.Next(0, answeringCards.Count)]);
                }
                else
                {
                    if (player.Cards.Count != 0)
                    {
                        return(player.Cards [rand.Next(player.Cards.Count)]);
                    }
                    else
                    {
                        return(SixtySixUtil.DrawCard(player, deck));
                    }
                }
            }
            else
            {
                return(player.Cards[rand.Next(0, player.Cards.Count)]);
            }
        }
Ejemplo n.º 2
0
        public static Card MakeTurn(Player player, Player opp, Deck deck, Card playedFromOther = null)
        {
            if (playedFromOther == null && player.HasWonLastHand)
            {
                //check for swapping opened card and swap if is allowed
                if (SixtySixUtil.CanSwap(player.Cards, deck))
                {
                    SixtySixUtil.SwapOpenedCard(player, deck);
                }
            }

            Card card = GetAITurn(player, opp, deck, playedFromOther);;

            //need to andswer
            if (playedFromOther != null && SixtySixUtil.HasToAnswerWithMatching(deck))
            {
                if (!card.Suit.Equals(playedFromOther.Suit) && SixtySixUtil.HasAnsweringCard(player, playedFromOther))
                {
                    do
                    {
                        Console.WriteLine("Wrong card to answer. The algorithm is trying again");
                        card = GetAITurn(player, opp, deck, playedFromOther);
                    } while (!card.Suit.Equals(playedFromOther.Suit));
                }
            }
            if (!player.IsSilent)
            {
                Console.WriteLine("AI Hand: " + player.ToStringPlayerCards());
                Console.WriteLine("AI has played: {0}", card);
            }
            player.GiveCard(card);

            return(card);
        }
Ejemplo n.º 3
0
        /*
         * In the context of this method player1 has always win last game
         *
         */
        public static int PlayOneDeal(Deck deck, Player player1, Player player2, Card cardOnTable)
        {
            while (player1.Cards.Count() > 0 && player2.Cards.Count() > 0)
            {
                if (player1.HasWonLastHand)
                {
                    MakeTurn(player1, player2, deck, cardOnTable);

                    if (SixtySixUtil.IsSixtySixReached(player1, player2))
                    {
                        break;
                    }
                }
                else if (player2.HasWonLastHand)
                {
                    MakeTurn(player2, player1, deck, cardOnTable);

                    if (SixtySixUtil.IsSixtySixReached(player2, player1))
                    {
                        break;
                    }
                }
            }
            return(player1.WinsCount - player2.WinsCount);
        }
Ejemplo n.º 4
0
        private static void MakeTurn(Player player1, Player player2, Deck deck, Card cardOnTable)
        {
            var card      = new Card();
            var otherCard = new Card();
            int handScore;

            //give card
            if (cardOnTable != null)
            {
                card      = AIMovementUtil.MakeTurn(player1, player2, deck, cardOnTable);
                otherCard = cardOnTable;
            }
            else
            {
                card = AIMovementUtil.MakeTurn(player1, player2, deck, cardOnTable);

                //Check for additional point -> (20 or 40)
                //TODO Idea for modification: Player choose if he wants to call his announce. If has more than one announce can choose which one wants to play.
                if (SixtySixUtil.HasForty(player1.Cards, card, deck))
                {
                    SixtySixUtil.CallForty(player1);
                }
                else if (SixtySixUtil.HasTwenty(player1.Cards, card, deck))
                {
                    SixtySixUtil.CallTwenty(player1);
                }
                otherCard = AIMovementUtil.MakeTurn(player2, player1, deck, card);
            }

            handScore = (int)card.Value + (int)otherCard.Value;

            deck.ThrownCards.Add(card);
            deck.ThrownCards.Add(otherCard);

            // player1 plays first, so if first card wins, then the first player wins
            if (SixtySixUtil.WinsFirstCard(card, otherCard, deck.TrumpSuit))
            {
                player1.Score         += handScore;
                player1.HasWonLastHand = true;
                player2.HasWonLastHand = false;
                SixtySixUtil.DrawCard(player1, deck);
                SixtySixUtil.DrawCard(player2, deck);
            }
            else
            {
                player2.Score         += handScore;
                player2.HasWonLastHand = true;
                player1.HasWonLastHand = false;
                SixtySixUtil.DrawCard(player2, deck);
                SixtySixUtil.DrawCard(player1, deck);
            }
        }
Ejemplo n.º 5
0
 public static bool IsSixtySixReached(Player player, Player other)
 {
     if (player.HasWonLastHand && player.Score >= Constants.TOTAL_SCORE)
     {
         player.WinsCount     += SixtySixUtil.GetNumberOfWins(other);
         player.HasWonLastDeal = true;
         other.HasWonLastDeal  = false;
         if (!player.IsSilent)
         {
             Console.WriteLine(player.ToString() + " has won!!");
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }