예제 #1
0
 public ScoreDisplay(ref GameData gameData)
 {
     this.currentRound = gameData.CurrentRound;
     playerList = gameData.CurrentPlayerList;
     scoreArray = gameData.score;
     InitializeComponent();
 }
예제 #2
0
        /// <summary>
        /// Bid Function of AI player 
        /// REFRENCE :: http://members.aol.com/loflyer/spades/#bidint
        /// </summary>
        /// <param name="gData"></param>
        /// <returns></returns>
        public override int Bid(GameData gData)
        {
            float count = 0;

            // NON SPADE BID

            int spadesCount = NumberOfCardInSuit(CardSuit.Spades, Hand);
            int ShortSuitBid = 0;

            foreach (CardSuit cardSuit in Enum.GetValues(typeof(CardSuit)))
            {
                if (cardSuit != CardSuit.Spades)
                {
                    int numberOfCardInSuit = NumberOfCardInSuit(cardSuit, Hand);
                    if (numberOfCardInSuit > 0)
                    {
                        // count +1 for card if its ace or king
                        if (HasCard(cardSuit, CardRank.Ace, Hand)) count = count + 1;
                        if (HasCard(cardSuit, CardRank.King, Hand)) count = count + 1;
                        if (RankBelow(cardSuit, Hand, CardRank.King) >= 4) count = count - 1;
                        else if (RankBelow(cardSuit, Hand, CardRank.King) == 3) count = count - (1 / 2);
                        if (RankBelow(cardSuit, Hand, CardRank.Ace) >= 6) count = count - 1;
                        else if (RankBelow(cardSuit, Hand, CardRank.Ace) == 5) count = count - (1 / 2);
                        if (HasCard(cardSuit, CardRank.King, Hand) && numberOfCardInSuit == 1) count = count - 1;
                        if (HasCard(cardSuit, CardRank.Ace, Hand) && HasCard(cardSuit, CardRank.Queen, Hand)) count = count + (1 / 2);
                    }
                    if (numberOfCardInSuit <= 2) ShortSuitBid = ShortSuitBid + (3 - numberOfCardInSuit);

                }
            }

            int tempSpadesCount = 0;
            int spadesBid = 0;
            if (spadesCount > 0)
            {

                int spadesCountBaseRank = 15 - spadesCount;

                tempSpadesCount = RankAbove(CardSuit.Spades, Hand, (CardRank)spadesCountBaseRank);

                int R = numberOfMissingSpades(spadesCountBaseRank + 1);

                int tempSubstract = 0;
                if (R > 0) tempSubstract = ShortSuitBid - R;

                spadesBid = (tempSubstract >= ShortSuitBid) ? ShortSuitBid : tempSubstract;

            }

            count = count + tempSpadesCount + spadesBid;

            if (count <= 0) count = 1; // minimum 1 bid must be there
            return (int)count;
        }
예제 #3
0
        /// <summary>
        /// Show Bid Dialog and sets the player BID
        /// </summary>
        /// <param name="gData"></param>
        /// <returns></returns>
        public override int Bid(GameData gData)
        {
            BidForm BF = new BidForm(gData);
            BF.StartPosition = FormStartPosition.CenterParent;

            if (BF.ShowDialog() == DialogResult.OK)
            {
                return (int)BF.BidTrackBar.Value;
            }

            else return 0;
        }
예제 #4
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;
        }
예제 #5
0
        /// <summary>
        /// AI makeMove function 
        /// It now randomly chooses a valid card.
        /// ToDO :: make this better
        /// </summary>
        /// <param name="gameData"></param>
        /// <returns></returns>
        public override SpadesCard makeMove(GameData gameData)
        {
            RandomAIStrategy strategy = new RandomAIStrategy();
            return strategy.makeMove(gameData);

            //base.makeMove();
        }
예제 #6
0
파일: Main.cs 프로젝트: nishesj/callbreak
 public void updateGameState(GameData gdata)
 {
     this.gameData = gdata;
     gameData.CurrentPot.PotAdd += new PotAddEventHandler(Pot_PotAdd);
     RefreshWholeBoard = true;
     if (gameData.GameState == GameState.BIDDING)
     {
         enterBiddingState();
     }
     else if (gameData.GameState == GameState.PLAYING)
     {
         enterPlayingState();
     }
     else if (gameData.GameState == GameState.ROUNDEND)
     {
         showScoreBoard();
     }
     else
     {
         redrawForm();
     }
 }
예제 #7
0
파일: player.cs 프로젝트: nishesj/callbreak
 /// <summary>
 /// Must be overridden by subclass
 /// </summary>
 /// <param name="gameData">GameData structure</param>
 /// <returns></returns>
 public virtual SpadesCard makeMove(GameData gameData)
 {
     return null;
 }
예제 #8
0
파일: player.cs 프로젝트: nishesj/callbreak
 /// <summary>
 /// Must be overridden by sub class to implement the bidding function i.e AI and Human 
 /// 
 /// </summary>
 /// <param name="gData">GameData Structure</param>
 /// <returns></returns>
 public virtual int Bid(GameData gData)
 {
     return 0;
 }
예제 #9
0
 public BiddingState(ref GameData gData)
 {
     gameData = gData;
     playerList = gameData.CurrentPlayerList;
 }
예제 #10
0
 public BidForm(GameData gData)
 {
     InitializeComponent();
     gameData = gData;
 }