public TableManagerTcpHost(int port, BridgeEventBus bus) : base(bus, "Host@" + port) { this.tcpclients = new List <TcpClientData>(); var listener = new TcpListener(IPAddress.Any, port); listener.Start(); listener.BeginAcceptTcpClient(new AsyncCallback(this.AcceptClient), listener); }
public void Connect(Seats _seat, string serverName, int portNumber, int _maxTimePerBoard, int _maxTimePerCard, string teamName, bool _sendAlerts) { var bus = new BridgeEventBus("TM_Client " + _seat); var bot = new ChampionshipRobot(_seat, bus); bus.HandleTournamentStarted(Scorings.scIMP, _maxTimePerBoard, _maxTimePerCard, ""); bus.HandleRoundStarted(new SeatCollection <string>(), new DirectionDictionary <string>("RoboBridge", "RoboBridge")); var connectionManager = new TableManagerTcpClient(bus); connectionManager.Connect(_seat, serverName, portNumber, _maxTimePerBoard, _maxTimePerCard, teamName); }
public static void HandleProtocolPlay(string message, BridgeEventBus bus) { // North plays 3C string[] answer = message.Split(' '); var player = SeatsExtensions.FromXML(answer[0]); var suit = SuitHelper.FromXML(answer[2][1]); var rank = Rank.From(answer[2][0]); bus.HandleCardPosition(player, suit, rank); bus.HandleCardPlayed(player, suit, rank); }
public async Task TableManagerClient_TestIsolated() { Log.Level = 3; Log.Debug("debug line should not be in a release build"); this.clientEventBus = new BridgeEventBus("TM_Client"); var client = new TestClient(this.clientEventBus); client.Connect(Seats.North, 120, 60, "RoboNS"); await client.WaitForCompletionAsync(); }
protected TableManagerHost(BridgeEventBus bus, string name) : base(bus, name) { this.clients = new SeatCollection <ClientData>(); this.moreBoards = true; this.lagTimer = new System.Diagnostics.Stopwatch(); this.ThinkTime = new DirectionDictionary <System.Diagnostics.Stopwatch>(new System.Diagnostics.Stopwatch(), new System.Diagnostics.Stopwatch()); this.boardTime = new DirectionDictionary <TimeSpan>(new TimeSpan(), new TimeSpan()); this.waiter = new SemaphoreSlim(initialCount: 0); Task.Run(async() => { await this.ProcessMessages(); }); }
public void TableManagerHost_IllegalSeatTest() { Log.Level = 2; this.hostEventBus = new BridgeEventBus("TM_Host"); var host = new TestHost(this.hostEventBus); host.OnHostEvent += Host_OnHostEvent; var north = new TestClient(host); host.State = 1; host.Seat(north, string.Format("Connecting \"WBridge5\" as ANYPL using protocol version 18")); host.Seat(north, string.Format("Connecting \"WBridge5\" as NORTH using protocol version 18")); }
public static void HandleProtocolBid(string message, BridgeEventBus bus) { // North passes // North doubles // North redoubles // North bids 1H // North bids 1H Alert. 13 to 19 total points. // North bids 1H Alert.C=0-8,D=4-8,H=0-5,S=0-5,HCP=17-19,Total=19-21. // North bids 1H.Infos.C=0-8,D=4-8,H=0-5,S=0-5,HCP=17-19,Total=19-21. bool bidWasAlerted = false; string bidPhrase; string alertPhrase = string.Empty; int startAlert = message.ToLower().IndexOf("alert."); if (startAlert == -1) { startAlert = message.ToLower().IndexOf("infos."); } if (startAlert >= 0) { bidWasAlerted = true; bidPhrase = message.Substring(0, startAlert).Trim(); //alertPhrase = Helpers.AlertFromTM(message.Substring(startAlert + 6).Trim()); alertPhrase = message.Substring(startAlert + 6).Trim(); } else { bidWasAlerted = false; bidPhrase = message.Trim(); } // 24-07-09: TableMoniteur adds a . after a bid: "North doubles." if (bidPhrase.EndsWith(".")) { bidPhrase = bidPhrase.Substring(0, bidPhrase.Length - 1); } string[] answer = bidPhrase.Split(' '); Seats bidder = SeatsExtensions.FromXML(answer[0]); var bid = new Bid(answer[answer.Length - 1], alertPhrase); if (bidWasAlerted) // && alertPhrase.Length == 0) { bid.NeedsAlert(); } bus.HandleBidDone(bidder, bid); }
public async Task TableManagerHost_Test() { Log.Level = 2; this.hostEventBus = new BridgeEventBus("TM_Host"); var host = new TestHost(this.hostEventBus); host.OnHostEvent += Host_OnHostEvent; host.State = 1; SeatsExtensions.ForEachSeat((s) => { var client = new TestClient(host); host.Seat(client, string.Format("Connecting \"{1}\" as {0} using protocol version 19", s, s.Direction())); }); host.State = 3; await host.WaitForCompletionAsync(); //host.ready.WaitOne(); host.stopped = true; }
protected TableManagerClient(BridgeEventBus bus) : base("TableManagerClient", bus) { if (bus == null) { throw new ArgumentNullException("bus"); } this.messages = new Queue <string>(); this.stateChanges = new Queue <StateChange>(); this._waitForBridgeEvents = false; this._waitForProtocolSync = false; this.moreBoards = true; this.waiter = new SemaphoreSlim(initialCount: 0); Task.Run(async() => { await this.ProcessMessages(); }); Task.Run(async() => { await this.ProcessStateChanges(); }); }
public void TableManagerHost_SeatingTest() { Log.Level = 2; this.hostEventBus = new BridgeEventBus("TM_Host"); var host = new TestHost(this.hostEventBus); host.OnHostEvent += Host_OnHostEvent; var north = new TestClient(host); host.State = 1; host.Seat(north, string.Format("Connecting \"{1}\" as {0} using protocol version 19", Seats.North, Seats.North.Direction())); host.State = 4; host.Seat(north, string.Format("Connecting \"{1}\" as {0} using protocol version 19", Seats.North, Seats.North.Direction())); var south = new TestClient(host); host.State = 2; host.Seat(south, string.Format("Connecting \"{1}\" as {0} using protocol version 19", Seats.South, Seats.South.Direction().ToString() + "2")); host.State = 1; host.Seat(south, string.Format("Connecting \"{1}\" as {0} using protocol version 19", Seats.South, Seats.South.Direction())); host.State = 3; }
public TestHost(BridgeEventBus bus) : base(bus, "TestHost") { }
public TestClient(BridgeEventBus bus) : base(bus) { this.testState = 1; }
public HostBoardResult(TableManagerHost h, Board2 board, SeatCollection <string> newParticipants, BridgeEventBus bus) : base("HostBoardResult", board, newParticipants, bus, null) { this.host = h; }
public TMController(TableManagerHost h, Tournament t, ParticipantInfo p, BridgeEventBus bus) : base(t, p, bus) { this.host = h; }
public TestRobot(Seats seat, BridgeEventBus bus) : base(seat, bus) { this.seat = seat; }
public TableManagerTcpClient(BridgeEventBus bus) : base(bus) { }
public ChampionshipRobot(Seats seat, BridgeEventBus bus) : base(seat, bus) { }
public TestClient(BridgeEventBus bus) : base(bus) { }
public TestHost(int port, BridgeEventBus bus) : base(port, bus) { }