예제 #1
0
        public SpadesCard makeMove(GameData gameData)
        {
            Pot pot = gameData.CurrentPot;
            List <SpadesCard> validCardList = new List <SpadesCard>();
            player            currentPlayer = gameData.CurrentPlayerList[gameData.ActivePlayerId];

            // make some move
            // get all valid card move to narrow down the search scope first

            if (pot.Count() == 0)
            {
                foreach (SpadesCard card in currentPlayer.Hand.CardPile)
                {
                    validCardList.Add(card);
                }// any hand card is valid to play ..
            }
            else
            {
                foreach (SpadesCard card in currentPlayer.Hand.CardPile)
                {
                    if (GameRule.isValidCard(currentPlayer, card, pot))
                    {
                        validCardList.Add(card);
                    }
                }
            }

            int count = validCardList.Count;


            // throw some random card now
            if (count > 0)
            {
                DateTime x    = DateTime.Now;
                float    mins = x.Minute;
                float    secs = x.Second;
                float    hour = x.Hour;
                if (gameData.ActivePlayerId != 0)
                {
                    rand = new Random(Convert.ToInt32(((secs * mins) + hour) / gameData.ActivePlayerId));
                }
                else
                {
                    rand = new Random(Convert.ToInt32(((secs * mins) + hour)));
                }

                SpadesCard c;

                int index = rand.Next(0, validCardList.Count - 1);
                c = (SpadesCard)validCardList[index];
                return(c);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// checks whether the card played by the player is valid or not in current scenario
        /// </summary>
        /// <param name="currentPlayer">The card player</param>
        /// <param name="playedCard">what card has the player chooosen to play </param>
        /// <param name="currentPot">pot of current running hand</param>
        /// <returns></returns>
        public static bool isValidCard(player currentPlayer,  SpadesCard playedCard, Pot currentPot)
        {
            // if pot is empty its the first card and is always valid
            if (currentPot.CardPile.Count == 0)
            {
                return true;
            }
            else
            {
                // get 1st played card

                SpadesCard first = (SpadesCard)currentPot.CardPile[0];

                // check if player has the same suit to play
                if (hasSuit(first.Suit, currentPlayer.Hand))
                {
                    if (first.Suit == playedCard.Suit)
                    {

                        if (first.Suit != CardSuit.Spades && currentPot.highestCard.Suit == CardSuit.Spades)
                        {
                            return true;
                        }
                        else
                        {
                            // check its higher than the higest card in the pile
                            if (playedCard.Rank == CardRank.Ace) return true;
                            else
                            {
                                if (playedCard.Rank > currentPot.highestCard.Rank) return true;
                                else
                                {
                                    // check if he has higher card in this hand
                                    if (checkHandForHigherCard(currentPot.highestCard, currentPlayer.Hand))
                                    {
                                        // player has other higher card
                                        return false;
                                    }
                                    else
                                    {
                                        return true;
                                    }

                                }
                            }
                        }

                    }
                    else return false;
                }
                // check if he has spades to play
                else if (hasSuit(CardSuit.Spades, currentPlayer.Hand))
                {

                    if (checkHandForHigherCard(currentPot.highestCard, currentPlayer.Hand))
                    {

                        if (currentPot.highestCard.Suit != CardSuit.Spades && playedCard.Suit == CardSuit.Spades) return true;
                        if (playedCard.Rank == CardRank.Ace && playedCard.Suit == CardSuit.Spades) return true;
                        if ((playedCard.Rank > currentPot.highestCard.Rank) && ((currentPot.highestCard.Suit == CardSuit.Spades) && (playedCard.Suit == CardSuit.Spades))) return true;

                        return false;
                    }

                  // if no higher card play any thing
                  return true;

                }
                // if nothing play anyhitng
                else return true;

            }
        }
예제 #3
0
        /// <summary>
        /// checks whether the card played by the player is valid or not in current scenario
        /// </summary>
        /// <param name="currentPlayer">The card player</param>
        /// <param name="playedCard">what card has the player chooosen to play </param>
        /// <param name="currentPot">pot of current running hand</param>
        /// <returns></returns>
        public static bool isValidCard(player currentPlayer, SpadesCard playedCard, Pot currentPot)
        {
            // if pot is empty its the first card and is always valid
            if (currentPot.CardPile.Count == 0)
            {
                return(true);
            }
            else
            {
                // get 1st played card



                SpadesCard first = (SpadesCard)currentPot.CardPile[0];

                // check if player has the same suit to play
                if (hasSuit(first.Suit, currentPlayer.Hand))
                {
                    if (first.Suit == playedCard.Suit)
                    {
                        if (first.Suit != CardSuit.Spades && currentPot.highestCard.Suit == CardSuit.Spades)
                        {
                            return(true);
                        }
                        else
                        {
                            // check its higher than the higest card in the pile
                            if (playedCard.Rank == CardRank.Ace)
                            {
                                return(true);
                            }
                            else
                            {
                                if (playedCard.Rank > currentPot.highestCard.Rank)
                                {
                                    return(true);
                                }
                                else
                                {
                                    // check if he has higher card in this hand
                                    if (checkHandForHigherCard(currentPot.highestCard, currentPlayer.Hand))
                                    {
                                        // player has other higher card
                                        return(false);
                                    }
                                    else
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                // check if he has spades to play
                else if (hasSuit(CardSuit.Spades, currentPlayer.Hand))
                {
                    if (checkHandForHigherCard(currentPot.highestCard, currentPlayer.Hand))
                    {
                        if (currentPot.highestCard.Suit != CardSuit.Spades && playedCard.Suit == CardSuit.Spades)
                        {
                            return(true);
                        }
                        if (playedCard.Rank == CardRank.Ace && playedCard.Suit == CardSuit.Spades)
                        {
                            return(true);
                        }
                        if ((playedCard.Rank > currentPot.highestCard.Rank) && ((currentPot.highestCard.Suit == CardSuit.Spades) && (playedCard.Suit == CardSuit.Spades)))
                        {
                            return(true);
                        }



                        return(false);
                    }



                    // if no higher card play any thing
                    return(true);
                }
                // if nothing play anyhitng
                else
                {
                    return(true);
                }
            }
        }