Exemplo n.º 1
0
            public override void HandleCardPlayed(Seats source, Suits suit, Ranks rank)
            {
#if syncTrace
                Log.Trace(4, "HostBoardResult.HandleCardPlayed {0} plays {2}{1}", source, suit.ToXML(), rank.ToXML());
#endif
                this.host.ThinkTime[source.Direction()].Stop();
                //this.host.boardTime[source.Direction()] = this.host.boardTime[source.Direction()].Add(timer.Elapsed.Subtract(new TimeSpan(this.host.clients[source].communicationLag)));
                base.HandleCardPlayed(source, suit, rank);
                for (Seats s = Seats.North; s <= Seats.West; s++)
                {
                    if ((s != source && !(s == this.Auction.Declarer && source == this.Play.Dummy)) ||
                        (s == source && source == this.Play.Dummy)
                        )
                    {
                        this.host.clients[s].WriteData("{0} plays {2}{1}", source, suit.ToXML(), rank.ToXML());
                    }

                    if (this.Play.currentTrick == 1 && this.Play.man == 2)
                    {   // 1st card: need to send dummies cards
#if syncTrace
                        //Log.Trace("HostBoardResult.HandleCardPlayed 1st card to {0}", s);
#endif
                        var mustPause = s == this.Play.Dummy;
                        lock (this.host.clients) this.host.clients[s].Pause = mustPause;
                        this.host.clients[s].state = s == this.Play.Dummy ? TableManagerProtocolState.GiveDummiesCards : TableManagerProtocolState.WaitForDummiesCards;
                    }
                }
            }
Exemplo n.º 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;
                    }
            }
Exemplo n.º 3
0
            public override void HandleCardNeeded(Seats controller, Seats whoseTurn, Suits leadSuit, Suits trump, bool trumpAllowed, int leadSuitLength, int trick)
            {
#if syncTrace
                //Log.Trace(4, "HostBoardResult.HandleCardNeeded");
#endif
                if (leadSuit == Suits.NoTrump)
                {
                    if (this.host.clients[controller].PauseBeforeSending)
                    {
                        Threading.Sleep(200);
                    }
                    this.host.clients[controller].WriteData("{0} to lead", whoseTurn == this.Play.Dummy ? "Dummy" : whoseTurn.ToXMLFull());
                }

                for (Seats s = Seats.North; s <= Seats.West; s++)
                {
                    this.host.clients[s].state = (s == controller ? TableManagerProtocolState.WaitForOwnCardPlay : TableManagerProtocolState.WaitForCardPlay);
                    lock (this.host.clients) this.host.clients[s].Pause = false;
                }

                this.host.ThinkTime[whoseTurn.Direction()].Start();
            }
Exemplo n.º 4
0
 public static bool IsSameDirection(this Seats s1, Seats s2)
 {
     return(s1.Direction() == s2.Direction());
 }
Exemplo n.º 5
0
 public override void HandleBidNeeded(Seats whoseTurn, Bid lastRegularBid, bool allowDouble, bool allowRedouble)
 {
     base.HandleBidNeeded(whoseTurn, lastRegularBid, allowDouble, allowRedouble);
     this.host.ThinkTime[whoseTurn.Direction()].Start();
 }