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);
        }