예제 #1
0
 public void UpdateRoundStatus(RoundStatus status, Card[][] allCards)
 {
     try
     {
         webClient.RecieveStatusCards(status, allCards);
     }
     catch (Exception e)
     {
     }
 }
예제 #2
0
        /// <summary>
        /// returns the highest value card that is lower than the card supplied value 
        /// </summary>
        /// <param name="cardsList">a list of cards (should all be same suit)</param>
        /// <param name="refCard">the card to compare to</param>
        /// <returns>the highest lower card</returns>
        private static Card GetHighestLowerCard(List<Card> cardsList, Card refCard)
        {
            Card chosen = default(Card);

            chosen = (from c in cardsList
                      where c.Value < refCard.Value
                      orderby c.Value descending
                      select c).FirstOrDefault();

            return chosen;
        }
        public override Card[] RequestExhangeCards()
        {
            double highestScore = 0;
            Card[] highestScoreCards = new Card[3];

            //check all sub-groups of 10 cards in cards
            for (int i = 2; i < 13; i++)
            {
                for (int j = 1; j < i; j++)
                {
                    for (int k = 0; k < j; k++)
                    {
                        //all suits
                        for (int s = 1; s <= 4; s++)
                        {
                            //create the collection of cards wanted to check
                            ICollection<Card> cards_cpy = new HashSet<Card>(Cards);
                            cards_cpy.Remove(Cards[i]);
                            cards_cpy.Remove(Cards[j]);
                            cards_cpy.Remove(Cards[k]);

                            //check the score of current collection
                            double score = GetHighestBidForTrump((Suit)s, cards_cpy);

                            //score is better?
                            if (score > highestScore)
                            {
                                //save new items
                                highestScoreCards[0] = Cards[i];
                                highestScoreCards[1] = Cards[j];
                                highestScoreCards[2] = Cards[k];
                                highestScore = score;
                            }
                        }
                    }
                }
            }

            return highestScoreCards;
        }
예제 #4
0
        /// <summary>
        /// Returns statistics of a player having an asked card (0 means - no chance)
        /// </summary>
        /// <param name="player">asked player</param>
        /// <param name="card">asked card</param>
        /// <returns></returns>
        protected double getCardStatistic(PlayerSeat player, Card card)
        {
            //check if player have suit?
            if (!getPlayerSuitStatus(player, card.Suit))
            {
                return 0;
            }

            //check if card was thrown before?
            if (m_playedCards[(int)card.Suit - 1].Contains(card.Value))
            {
                return 0;
            }

            //check if card was played in this play?
            for (int i = (int)CurrentRoundStatus.LeadingPlayer; i < 4; i++)
            {
                Card? tmp = CurrentRoundStatus.CurrentPlay[i % 4];
                if (tmp != null)
                {
                    m_playedCards[(int)tmp.Value.Suit - 1].Add(tmp.Value.Value);

                    if (CurrentRoundStatus.CurrentPlay[i % 4].Equals(card))
                    {
                        return 0;
                    }
                }
                else
                {
                    break;
                }
            }

            //card was not thrown yet. calculate statistics (acctually left!=0 otherwise we already returned... but who cares...)
            int left = (13 - m_playedCards[(int)card.Suit - 1].Count);
            double retVal = (left == 0) ? 0 : 1/left;

            return retVal;
        }
예제 #5
0
        public void ShowRoundStatus(RoundStatus status, Card[][] allCards)
        {
            lbl_trump.Text = status.Trump.HasValue ? status.Trump.Value.ToString() : "No-suit" ;

            lbl_bid_self.Text = GetBiddingText(status.State == RoundState.Bidding,  status.Biddings[0]);
            lbl_bid_west.Text = GetBiddingText(status.State == RoundState.Bidding, status.Biddings[1]);
            lbl_bid_north.Text = GetBiddingText(status.State == RoundState.Bidding, status.Biddings[2]);
            lbl_bid_east.Text = GetBiddingText(status.State == RoundState.Bidding, status.Biddings[3]);

            lbl_tricks_self.Text = status.TricksTaken[0] + "";
            lbl_tricks_west.Text = status.TricksTaken[1] + "";
            lbl_tricks_north.Text = status.TricksTaken[2] + "";
            lbl_tricks_east.Text = status.TricksTaken[3] + "";

            SetCardImage(play_self, status.CurrentPlay[0]);
            SetCardImage(play_west, status.CurrentPlay[1]);
            SetCardImage(play_north, status.CurrentPlay[2]);
            SetCardImage(play_east, status.CurrentPlay[3]);

            SetAllCardsToPlayer(cards_self, allCards[0]);
            SetAllCardsToPlayer(cards_west, allCards[1]);
            SetAllCardsToPlayer(cards_north, allCards[2]);
            SetAllCardsToPlayer(cards_east, allCards[3]);
        }
예제 #6
0
 public virtual void RecieveExchangeCards(Card[] cards)
 {
     Cards.AddRange(cards);
 }
예제 #7
0
 public virtual void RecieveCards(Card[] cards)
 {
     Cards = new List<Card>(cards);
 }
예제 #8
0
 public void InvokeOnGetPlayCompleted(Card play)
 {
     ResponseRecieved();
     if (OnGetPlayCompleted != null)
         OnGetPlayCompleted(this, new RecievePlayEventArgs(play));
 }
예제 #9
0
 public void InvokeOnGetExchangedCardsCompleted(Card[] cards)
 {
     ResponseRecieved();
     if (OnGetExchangedCardsCompleted != null)
         OnGetExchangedCardsCompleted(this, new RecieveCardsEventArgs(cards));
 }
예제 #10
0
 private void SetAllCardsToPlayer(Panel list, Card[] card)
 {
     list.Controls.Clear();
     int y = 0;
     int x = 0;
     var arranged = (from c in card
                     orderby (c.Suit != Suit.Hearts ? (int)c.Suit : 5), c.Value
                     select c).ToArray();
     foreach (Card c in arranged)
     {
         PictureBox box = new PictureBox();
         box.Width = 36;
         box.Height = 46;
         box.Location = new Point(x, y);
         if (list.Height > 100)
             y += 50;
         else
             x += 38;
         box.SizeMode = PictureBoxSizeMode.StretchImage;
         box.Image = GetImageForCard(c);
         list.Controls.Add(box);
     }
 }
예제 #11
0
 /// <summary>
 /// happens at the end of each round - insert played cards to memory
 /// </summary>
 /// <param name="roundCards">played cards</param>
 private void updateMemory(Card?[] roundCards)
 {
     foreach (Card c in roundCards)
     {
         m_playedCards[(int)c.Suit - 1].Add(c.Value);
     }
 }
예제 #12
0
 public RecievePlayEventArgs(Card play)
     : base()
 {
     this.Play = play;
 }
예제 #13
0
 public void RecieveCards(Card[] cards)
 {
     this.cards = new List<Card>(cards);
 }
예제 #14
0
 public void UpdateRoundStatus(RoundStatus status, Card[][] allCards)
 {
     //BeginInvoke(new MethodInvoker( delegate() { ShowRoundStatus(status, allCards); }));
     statusHistory.Add(new status_and_cards{ Status = status.Clone(), Cards = (Card[][])allCards.Clone() });
 }
예제 #15
0
        /// <summary>
        /// calculate the cumulative chance that we lose the hand with this card
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        private double ChanceToLoseTheHand(Card card)
        {
            double ret = 0;

            //case that on board there's a higher card with same suit, it's a sure lose, return 1
            foreach (Card? c in CurrentRoundStatus.CurrentPlay)
            {
                if (c.HasValue && c.Value.Suit == card.Suit && c.Value.Value > card.Value)
                {
                    return 1;
                }
            }

            //get the players who didn't play yet
            List<PlayerSeat> toPlay = new List<PlayerSeat>();
            for (int i = 1; i < 4; i++)
            {
                if (!CurrentRoundStatus.CurrentPlay[i].HasValue)
                {
                    toPlay.Add((PlayerSeat)i);
                }
            }

            //if someone cut the round, and our card is not a trump, it's a sure lose, return 1
            //if someone who didn't play yet has only trumps left, it's a sure lose, return 1
            if (CurrentRoundStatus.Trump.HasValue)
            {
                foreach (Card? c in CurrentRoundStatus.CurrentPlay)
                {
                    if (c.HasValue && c.Value.Suit == CurrentRoundStatus.Trump)
                    {
                        if (card.Suit != CurrentRoundStatus.Trump)
                        {
                            return 1;
                        }
                    }
                }

                ////check if some player has only trumps left, and he didn't play yet
                //for (PlayerSeat p = PlayerSeat.West ; p <= PlayerSeat.East; p++)
                //{
                //    if (!CurrentRoundStatus.CurrentPlay[(int)p].HasValue)
                //    {
                //        bool hasOtherSuit = false;

                //        for (Suit suit = Suit.Clubs; suit <= Suit.Spades; suit++)
                //        {
                //            if (suit != CurrentRoundStatus.Trump.Value && getPlayerSuitStatus(p, suit))
                //            {
                //                hasOtherSuit = true;
                //            }
                //        }

                //        if (!hasOtherSuit)
                //        {
                //            return 1;
                //        }
                //    }
                //}
            }

            //so far we know that: noone trumped with a higher card, no higher card on board, and noone will surely trump us
            //means we must check statistics

            //create all cards who weren't thrown yet from our cards suit
            List<Card> nominees = new List<Card>();
            for (int i = 2; i <= 14; i++)
            {
                Card c = new Card(card.Suit, i);
                if (!m_playedCards[SuitIndex(c.Suit)].Contains(c.Value) && Cards.Contains(c))
                {
                    nominees.Add(c);
                }
            }

            //if someone else started the round
            if (CurrentRoundStatus.LeadingPlayer != PlayerSeat.Self)
            {
                int cardsFromSuitOnBoard = 0;

                foreach (Card? c in CurrentRoundStatus.CurrentPlay)
                {
                    if (c.HasValue && c.Value.Suit == card.Suit)
                    {
                        cardsFromSuitOnBoard++;
                    }
                }

                //if all cards left from this suit are in our hand
                if (ArrangeCardBySuits(Cards)[SuitIndex(card.Suit)].Count() + m_playedCards[SuitIndex(card.Suit)].Count() == 13)
                {
                    //return 1 if we trump, otherwise 0 (no higher card on board was checked before)
                    //TODO if we trump it, maybe others trump as well. check this out in new version
                    if (CurrentRoundStatus.Trump.HasValue && card.Suit == CurrentRoundStatus.Trump.Value)
                    {
                        return 0;
                    }
                    else //means we won't trump this round
                    {
                        return 1;
                    }
                }

                //if we're the last to play, and noone has a higher card than our card
                if (toPlay.Count == 0)
                {
                    //case we're playing the leading suit, means we have highest card therefore chance to lose is 0
                    if (card.Suit == CurrentRoundStatus.GetCurrentPlaySuit().Value)
                    {
                        return 0;
                    }
                    //case we're playing another suit
                    else
                    {
                        return 1;
                    }
                }

                //if some player has a card from wanted suit, and maybe some other players played
                else
                {

                    double totalProb = 0;

                    foreach (PlayerSeat p in toPlay)
                    {
                        foreach (Card c in nominees)
                        {
                            if (c.Value > card.Value)
                            {
                                totalProb += getCardStatistic(p,c);
                            }
                        }
                    }

                    totalProb /= toPlay.Count;
                    ret = totalProb;
                }

            }

            //if we started the round
            //means no cards from suit on board, and noone has only trumps left or this suit over
            else
            {
                //for a game with trumps, when leading a non-trump
                if (CurrentRoundStatus.Trump.HasValue && card.Suit != CurrentRoundStatus.Trump.Value)
                {
                    int relevant = 0, cutters = 0;
                    double totalProb = 0;

                    for (PlayerSeat p = PlayerSeat.West; p <= PlayerSeat.East; p++)
                    {
                        //if a player has our suit
                        if (getPlayerSuitStatus(p, card.Suit))
                        {
                            relevant++;
                            foreach (Card c in nominees)
                            {
                                if (c.Value > card.Value)
                                {
                                    totalProb += getCardStatistic(p, c);
                                }
                            }
                        }

                        //if a player doesn't have our suit
                        else
                        {
                            //if the player is able to trump us
                            if (getPlayerSuitStatus(p, CurrentRoundStatus.Trump.Value))
                            {
                                //add chance to random trump-throw
                                cutters++;

                                //TODO logic may assume smart player or no smart player (total rounds taken)
                                //here we will assume smartness

                            }

                            //if the player isn't able to trump us, don't calculate him in the percentage count
                            else
                            {

                            }
                        }
                    }
                    //if noone will trump us, and noone has cards from our suit
                    if (relevant == 0 && cutters == 0)
                    {
                        return 0;
                    }

                    if (relevant != 0)
                    {
                        //average total probability over relevant players
                        totalProb /= relevant;
                    }

                    if (cutters != 0)
                    {
                        //add chance that we'll be cut over: number of trumps left  - round left
                        totalProb += (13 - m_playedCards[SuitIndex(CurrentRoundStatus.Trump.Value)].Count) / (cutters * (13 - CurrentRoundStatus.TurnNumber + 1));
                    }

                }

                //for a game with no-trump, or trying to lead a trump
                else
                {
                    double totalProb = 0;
                    int relevant = 0;
                    for (PlayerSeat p = PlayerSeat.West; p <= PlayerSeat.East; p++)
                    {
                        if (getPlayerSuitStatus(p, card.Suit))
                        {
                            relevant++;

                            foreach (Card c in nominees) {
                                totalProb += getCardStatistic(p, c);
                            }
                        }
                    }
                    totalProb /= relevant;
                    ret = totalProb;
                }
            }

            return ret;
        }
예제 #16
0
 private void SetCardImage(PictureBox play_self, Card? card)
 {
     if (card.HasValue)
     {
         play_self.Image = GetImageForCard(card.Value);
     }
     else
         play_self.Image = null;
 }
예제 #17
0
 protected virtual void PassCards(Card card1, Card card2, Card card3)
 {
     Cards.Remove(card1);
     Cards.Remove(card2);
     Cards.Remove(card3);
 }
예제 #18
0
 public void RecieveExchangeCards(Card[] cards)
 {
     this.cards.AddRange(cards);
 }
예제 #19
0
 protected virtual void ThrowCard(Card card)
 {
     Cards.Remove(card);
 }
예제 #20
0
 public void RecieveExchangeCards(Card[] cards)
 {
     this.imp.RecieveExchangeCards(cards);
 }
예제 #21
0
 public RecieveCardsEventArgs(Card[] cards)
     : base()
 {
     this.Cards = cards;
 }
예제 #22
0
 public void RecieveExchangeCards(Card[] cards)
 {
     try
     {
         this.webClient.RecieveExchangedCards(cards);
     }
     catch (Exception e)
     {
     }
 }
예제 #23
0
 public void UpdateRoundStatus(RoundStatus status, Card[][] allCards)
 {
 }
예제 #24
0
 private Image GetImageForCard(Card card)
 {
     return GetImageList(card.Suit)[card.Value-2];
 }