Beispiel #1
0
        public Dictionary <string, string> GenerateAuctionsForShape()
        {
            var auctions = new Dictionary <string, string>();

            for (int spades = 0; spades < 8; spades++)
            {
                for (int hearts = 0; hearts < 8; hearts++)
                {
                    for (int diamonds = 0; diamonds < 8; diamonds++)
                    {
                        for (int clubs = 0; clubs < 8; clubs++)
                        {
                            if (spades + hearts + diamonds + clubs == 13)
                            {
                                var hand            = new string('x', spades) + "," + new string('x', hearts) + "," + new string('x', diamonds) + "," + new string('x', clubs);
                                var suitLengthSouth = hand.Split(',').Select(x => x.Length);
                                var str             = string.Join("", suitLengthSouth);

                                if (!IsFreakHand(str))
                                {
                                    var auction = BidManager.GetAuction(hand, new BidGenerator(), fasesWithOffset);
                                    auctions.Add(auction.GetBidsAsString(Player.South, x => x.Value[Player.South].fase == Fase.Shape), str);
                                }
                            }
                        }
                    }
                }
            }
            return(auctions);
        }
Beispiel #2
0
        public void Execute(HandsNorthSouth[] hands, Dictionary <string, string> shapeAuctions, Dictionary <string, List <string> > controlsAuctions)
        {
            this.shapeAuctions    = shapeAuctions;
            this.controlsAuctions = controlsAuctions;

            handPerAuction.Clear();

            var stopwatch     = Stopwatch.StartNew();
            var stringbuilder = new StringBuilder();

            foreach (var hand in hands)
            {
                try
                {
                    var auction = BidManager.GetAuction(hand.SouthHand, bidGenerator, fasesWithOffset);
                    AddHandAndAuction(hand, auction);
                }
                catch (Exception exception)
                {
                    stringbuilder.AppendLine(exception.Message);
                }
            }
            stringbuilder.AppendLine(@$ "Seconds elapsed: {stopwatch.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture)}
Duplicate auctions are written to " "HandPerAuction.txt" "
Statistics are written to " "Statistics.txt" "
Error info for hand-matching is written to " "ExpectedSouthHands.txt" "");
            SaveAuctions();

            MessageBox.Show(stringbuilder.ToString(), "Batch bidding done");
        }
Beispiel #3
0
        public void UpdateBiddingState(int bidIdFromRule, Fase nextfase, string description)
        {
            var bidId = bidIdFromRule + relayBidIdLastFase + FaseOffset;

            if (bidIdFromRule == 0)
            {
                currentBid   = Bid.PassBid;
                EndOfBidding = true;
                return;
            }

            currentBid             = BidManager.GetBid(bidId);
            currentBid.fase        = fase;
            currentBid.description = description;

            if (nextfase != fase)
            {
                relayBidIdLastFase = bidId + 1;
                fase             = nextfase;
                FaseOffset       = 0;
                nextBidIdForRule = 0;
            }
            else if (fasesWithOffset[fase])
            {
                FaseOffset++;
                nextBidIdForRule = bidIdFromRule;
            }
            else
            {
                nextBidIdForRule = bidIdFromRule + 1;
            }
        }
Beispiel #4
0
        private void ButtonGetAuctionClick(object sender, EventArgs e)
        {
            Clear();
            var orderedCards = unOrderedCards.OrderByDescending(x => x.Suit).ThenByDescending(c => c.Face, new FaceComparer());
            var handsString  = Common.GetDeckAsString(orderedCards);

            auctionControl.auction = BidManager.GetAuction(handsString, bidGenerator, fasesWithOffset);
            auctionControl.ReDraw();
            biddingBox.Enabled = false;
        }
Beispiel #5
0
        private void BidTillSouth(Auction auction, BiddingState biddingState)
        {
            // West
            auction.AddBid(Bid.PassBid);
            // North
            BidManager.NorthBid(biddingState);
            auction.AddBid(biddingState.currentBid);
            // East
            auction.AddBid(Bid.PassBid);

            auctionControl.ReDraw();
            biddingBox.UpdateButtons(biddingState.currentBid, auctionControl.auction.currentPlayer);
        }
Beispiel #6
0
        public Dictionary <string, List <string> > GenerateAuctionsForControls()
        {
            string[] controls = new[] { "", "A", "K", "Q", "AK", "AQ", "KQ", "AKQ" };

            var poss = new List <string[]>();

            foreach (var spade in controls)
            {
                foreach (var hearts in controls)
                {
                    foreach (var diamonds in controls)
                    {
                        foreach (var clubs in controls)
                        {
                            var c = spade + hearts + diamonds + clubs;

                            if (c.Count(x => x == 'A') * 2 + c.Count(x => x == 'K') > 1)
                            {
                                poss.Add(new string[] { spade, hearts, diamonds, clubs });
                            }
                        }
                    }
                }
            }
            ;

            var auctions = new Dictionary <string, List <string> >();

            foreach (var pos in poss)
            {
                var hand =
                    pos[0] + new string('x', 4 - pos[0].Length) + ',' +
                    pos[1] + new string('x', 3 - pos[1].Length) + ',' +
                    pos[2] + new string('x', 3 - pos[2].Length) + ',' +
                    pos[3] + new string('x', 3 - pos[3].Length);
                Debug.Assert(hand.Length == 16);

                var    auction = BidManager.GetAuction(hand, new BidGenerator(), fasesWithOffset);
                string key     = auction.GetBidsAsString(Player.South, x => x.Value[Player.South].fase != Fase.Shape);
                if (!auctions.ContainsKey(key))
                {
                    auctions.Add(key, new List <string>());
                }
                auctions[key].Add(hand);
            }

            return(auctions);
        }
Beispiel #7
0
        private void ShowBiddingBox()
        {
            void handler(object x, EventArgs y)
            {
                var biddingBoxButton = (BiddingBoxButton)x;

                BidManager.SouthBid(biddingState, handsString, bidGenerator);
                if (biddingBoxButton.bid != biddingState.currentBid)
                {
                    MessageBox.Show($"The correct bid is {biddingState.currentBid}. Description: {biddingState.currentBid.description}.", "Incorrect bid");
                }

                auctionControl.AddBid(biddingState.currentBid);
                BidTillSouth(auctionControl.auction, biddingState);
            }

            biddingBox = new BiddingBox(handler)
            {
                Parent = this,
                Left   = 50,
                Top    = 200
            };
            biddingBox.Show();
        }