/// <summary>
        /// Plays a card from the given player's hand.
        /// </summary>
        /// <param name="player">The player playing the card. Player's hand must con</param>
        /// <param name="card"></param>
        /// <returns></returns>
        public bool PlayCard(HanabiPlayer player, int cardIndex)
        {
            var card = Players[player.ID].Hand[cardIndex];

            Players[GetPlayerID(player)].Hand.RemoveAt(cardIndex);
            DrawCard(player);
            if (IsPlayable(card))
            {
                Players[player.ID].Action(this, card, true, true);
                PlayedCards.Add(card);
                if (card.Number == highestCard && HintsRemaining < 8)
                {
                    HintsRemaining++;
                }
                if (Score == 25)
                {
                    Ended = true;
                }
                return(true);
            }
            else
            {
                Players[player.ID].Action(this, card, true, false);
                BombsUsed++;
                if (BombsUsed >= 4)
                {
                    Ended = true;
                }
                return(false);
            }
        }
 public static List <HanabiCard> OrderedPlays(HanabiGame game, HanabiPlayer player)
 {
     return(player.Hand.Where(card => game.IsPlayable(card))
            .OrderBy(card => card.Number)
            .ThenBy(card => IsDangerCard(game, card))
            .ThenByDescending(card => player.Hand.IndexOf(card)).ToList());
 }
 public static HanabiAction FromMod8Value(HanabiPlayer player, int value)
 {
     if (value >= 4)
     {
         return(new HanabiAction(HanabiActionType.Discard, player.Hand[PosMod(value - 4, 4)], PosMod(value - 4, 4)));
     }
     else
     {
         return(new HanabiAction(HanabiActionType.Play, player.Hand[PosMod(value, 4)], PosMod(value, 4)));
     }
 }
            public void SetActionFromClue(HanabiPlayer cluer, ref HanabiGame game, int clueValue)
            {
                int seenvalue = 0;

                foreach (Mod8HanabiPlayer player in game.Players.Where(p => p != this && p != cluer))
                {
                    seenvalue += player.EvaluateHand(ref game).ToMod8Value();
                }
                int personalvalue = PosMod((clueValue - seenvalue), 8);

                this.NextAction = HanabiAction.FromMod8Value(this, personalvalue);
            }
 public void DrawCard(HanabiPlayer p)
 {
     if (Deck.Count != 0)
     {
         Players[GetPlayerID(p)].Hand.Add(Deck[0]);
         Deck.RemoveAt(0);
     }
     if (!DeckEmpty && Deck.Count == 0)
     {
         DeckEmpty = true;
     }
 }
        public void DiscardCard(HanabiPlayer player, int cardIndex)
        {
            var card = player.Hand[cardIndex];

            Players[player.ID].Hand.RemoveAt(cardIndex);
            DiscardedCards.Add(card);
            Players[player.ID].Action(this, card, false);
            DrawCard(player);
            if (HintsRemaining < 8)
            {
                HintsRemaining++;
            }
        }
            public static HanabiCard PreferredPlay(HanabiGame game, HanabiPlayer player)
            {
                var playableCards = OrderedPlays(game, player);

                if (playableCards.Count == 0)
                {
                    return(null);
                }
                else
                {
                    return(playableCards[0]);
                }
            }
 public int GetPlayerID(HanabiPlayer player)
 {
     return(player.ID);
 }
            public static HanabiCard PreferredDiscard(HanabiGame game, HanabiPlayer player)
            {
                var discards = OrderedDiscards(game, player).ToList();

                return(discards[0]);
            }
 //Discard priorities:
 public static IOrderedEnumerable <HanabiCard> OrderedDiscards(HanabiGame game, HanabiPlayer player)
 {
     return(player.Hand.OrderByDescending(card => game.PlayedCards.ContainsCard(card))
            .ThenBy(card => IsDangerCard(game, card))
            .ThenBy(card => player.Hand.Count(p => p.Color == card.Color && p.Number == card.Number) == 2)
            .ThenByDescending(card => card.Number)
            .ThenBy(card => player.Hand.IndexOf(card)));
 }