示例#1
0
        /// <summary>
        /// Play a card
        /// </summary>
        /// <param name="playerIndex">Player that is making the play</param>
        /// <param name="card">The card to play</param>
        /// <returns>True on success</returns>
        public bool Play(int playerIndex, Card card)
        {
            if (IsChanging || !Rules.ValidPlay(playerIndex, card))
            {
                return(false);
            }

            IsChanging = true;

            game.CurrentPlayer = -1;

            Player player = game.GetPlayerByIndex(playerIndex);

            player.Hand.Remove(card);

            TrickItem trickItem = new TrickItem(playerIndex, card);

            game.CurrentTrick.Add(trickItem);

            IsChanging = false;

            OnGameChanged(new GameChangedEventArgs(GameAction.Play, playerIndex));

            return(true);
        }
示例#2
0
        private TrickItem High(IList <TrickItem> trick)
        {
            TrickItem high = null;

            if (trick.Count > 0)
            {
                CardSuit leadingSuit = trick[0].Card.Suit;
                high = trick.Where(x => x.Card.Suit == leadingSuit)
                       .OrderBy(x => x.Card.Value)
                       .LastOrDefault();
            }
            return(high);
        }
示例#3
0
        protected override Card GetCardsToPlay(GameManager gameManager, int playerIndex)
        {
            Card         card      = null;
            Game         game      = gameManager.Game;
            Player       player    = game.GetPlayerByIndex(playerIndex);
            IList <Card> validHand = gameManager.Rules.ValidCards(playerIndex);
            IList <Card> hand      = game.GetPlayerByIndex(playerIndex).Hand;
            Card         qsCard    = new Card(CardSuit.Spades, CardValue.Queen);

            if (game.TrickHistory.Count == 0) //first trick
            {
                card = validHand.OrderByDescending(x => x.Value).First();
            }
            else if (!QueenOfSpadesHasBeenPlayed(game))
            {
                List <Card> highSpades = validHand.Where(x => x.Suit == CardSuit.Spades && x.Value >= CardValue.Queen).ToList();
                if (highSpades.Count == 0 && validHand.Any(x => x.Suit == CardSuit.Spades) && BleedingOutSpades(game, player))
                {
                    card = validHand.Where(x => x.Suit == CardSuit.Spades).First();
                }
                else if (highSpades.Count > 0)
                {
                    foreach (Card c in highSpades.OrderByDescending(x => x.Value))
                    {
                        if (CanDumpCard(gameManager, c))
                        {
                            card = c;
                        }
                    }
                }
            }

            if (card == null)
            {
                TrickItem high          = High(game.CurrentTrick);
                bool      hasHighSpades = hand.Any(x => x.Suit == CardSuit.Spades && x.Value >= CardValue.Queen);

                if (hasHighSpades && high == null)
                {
                    card = validHand.Where(x => x.Suit != CardSuit.Spades).OrderBy(x => x.Value).FirstOrDefault();
                }
                else
                {
                    if (high == null)
                    {
                        card = validHand.OrderBy(x => x.Value).FirstOrDefault();
                    }
                    else
                    {
                        card = validHand.Where(x => x.Value < high.Card.Value || x.Suit != high.Card.Suit)
                               .OrderByDescending(x => x.Value)
                               .FirstOrDefault();
                    }
                }
            }

            if (card == null && game.CurrentTrick.Count == 3)
            {
                card = validHand.OrderByDescending(x => x.Value).FirstOrDefault(x => !x.Equals(qsCard));
            }

            if (card == null)
            {
                card = validHand.OrderBy(x => x.Value).First();
            }

            return(card);
        }