コード例 #1
0
        public void Record(Seats s, Suits c, Ranks r, string comment)
        {
            lastPlay++;
            var p = (play.Count == lastPlay ? new PlayRecord() : play[lastPlay]);

            p.seat    = s;
            p.Suit    = c;
            p.Rank    = r;
            p.man     = man;
            p.trick   = currentTrick;
            p.Comment = comment;
            if (play.Count == lastPlay)
            {
                play.Add(p);
            }
            else
            {
                play[lastPlay] = p;
            }

            if (man == 1)
            {
                leadSuit = c;
            }

            if ((man == 1) || (c == bestSuit && r > bestRank) || (c != bestSuit && c == finalContract.Bid.Suit))
            {
                bestSuit = c;
                bestRank = r;
                bestMan  = s;
            }

            if (man == 4)
            {
                man = 1;
                currentTrick++;
                remainingTricks--;
                leadSuit  = Suits.NoTrump;
                whoseTurn = bestMan;
#if strict
                if (this.finalContract.tricksForDeclarer + this.finalContract.tricksForDefense + this.remainingTricks > 12)
                {
                    throw new FatalBridgeException("PlaySequence.Record: tricks > 12");
                }
#endif
                if (bestMan == declarer || bestMan == declarersPartner)
                {
                    this.finalContract.tricksForDeclarer++;
                }
                else
                {
                    this.finalContract.tricksForDefense++;
                }
            }
            else
            {
                man++;
                whoseTurn = whoseTurn.Next();
            }
        }
コード例 #2
0
            public override void HandleBidDone(Seats source, Bid bid)
            {
                this.host.ThinkTime[source.Direction()].Stop();
#if syncTrace
                Log.Trace(4, "HostBoardResult.HandleBidDone");
#endif
                if (this.BidMayBeAlerted(bid))
                {
                    //if (!bid.Alert || string.IsNullOrWhiteSpace(bid.Explanation))
                    {
#if syncTrace
                        Log.Trace(2, "HostBoardResult.HandleBidDone explain opponents bid");
#endif
                        this.host.ExplainBid(source, bid);
                        if (bid.Alert
                            //&& string.IsNullOrWhiteSpace(bid.Explanation)
                            )
                        {   // the operator has indicated this bid needs an explanation
                            Log.Trace(2, "HostBoardResult.HandleBidDone host operator wants an alert");
                            if (this.host.clients[source].CanAskForExplanation)
                            {   // client implements this new part of the protocol
                                var answer = this.host.clients[source.Next()].WriteAndWait("Explain {0}'s {1}", source, ProtocolHelper.Translate(bid));
                                bid.Explanation = answer;
                            }
                        }
                        else
                        {
                            Log.Trace(2, "HostBoardResult.HandleBidDone host operator does not want an alert");
                        }
                    }
                }

                base.HandleBidDone(source, bid);
                for (Seats s = Seats.North; s <= Seats.West; s++)
                {
                    this.host.clients[s].state = TableManagerProtocolState.WaitForMyCards;
                    if (s != source)
                    {
                        if (bid.Alert && s.IsSameDirection(source))
                        {   // remove alert info for his partner
                            var unalerted = new Bid(bid.Index, "", false, "");
                            this.host.clients[s].WriteData(ProtocolHelper.Translate(unalerted, source));
                        }
                        else
                        {
                            this.host.clients[s].WriteData(ProtocolHelper.Translate(bid, source));
                        }
                    }
                }

                lock (this.host.clients) for (Seats s = Seats.North; s <= Seats.West; s++)
                    {
                        this.host.clients[s].Pause = this.Auction.Ended;
                    }
            }
コード例 #3
0
 public PlaySequence(Contract bidResult, int tricksRemaining)
     : this()
 {
     if (bidResult == null)
     {
         throw new ArgumentNullException("bidResult");
     }
     finalContract    = bidResult;
     declarer         = finalContract.Declarer;
     declarersPartner = declarer.Partner();
     whoseTurn        = declarer.Next();
     leadSuit         = Suits.NoTrump;
     remainingTricks  = (byte)tricksRemaining;
 }
コード例 #4
0
        //-------------------------------------------------------------------------------
        public void DealRemainingCards(ShufflingRequirement requirement)
        {
            this.InitCardDealing();
            Seats receiver = Seats.North;

            while (lastCard < 51)
            {
                if (Length(receiver) < 13)
                {
                    int randomCard = 51 - RandomGenerator.Next(51 - lastCard);
                    Give(receiver, deal[randomCard].Suit, deal[randomCard].Rank);
                }

                receiver = receiver.Next();
            }
        }