public static Message Read(this IBotInterface bot) { if (bot == null) { throw new ArgumentNullException(nameof(bot)); } var data = bot.ReadLine(); return(JsonConvert.DeserializeObject <Message>(data)); }
public AsyncBotInterface(string apiKey, int timeOutMillisecs) { _botInterface = RemoteBotClientInitializer.Init(apiKey, false); _getInput = new AutoResetEvent(false); _gotInput = new AutoResetEvent(false); _timeOutMillisecs = timeOutMillisecs; var inputThread = new Thread(Reader) { IsBackground = true }; inputThread.Start(); }
public static T Read <T>(this IBotInterface bot) where T : IServerInfo { if (bot == null) { throw new ArgumentNullException(nameof(bot)); } var message = bot.Read(); var serverInfo = JsonConvert.DeserializeObject <T>(message.JsonPayload); if (serverInfo.Type != message.Type) { throw new MessageException($"Expected ${typeof(T)}, received ${message.Type}."); } return(serverInfo); }
public static void Write(this IBotInterface bot, Move move) { if (bot == null) { throw new ArgumentNullException(nameof(bot)); } if (move == null) { throw new ArgumentNullException(nameof(move)); } var message = new Message { Type = move is PassMove ? MessageType.Pass : MessageType.MovePiece, JsonPayload = JsonConvert.SerializeObject(move), }; var data = JsonConvert.SerializeObject(message); bot.WriteLine(data); }
private static void forciblyCloseRemoteBot(IBotInterface botInterface) { // This is not very nice, but there seems to be no other way // to disconnect. And without disconnecting, you can't even // kill the console app without force-quitting it. So it'll // have to do. try { var remoteBotClient = botInterface as RemoteBotClient.RemoteBotClient; var field = remoteBotClient.GetType().GetField("_client", BindingFlags.Instance | BindingFlags.NonPublic); var client = field.GetValue(remoteBotClient); var lidclient = client as Lidgren.Network.NetClient; lidclient.Disconnect("Adios!"); Task.Delay(500).Wait(); } catch (Exception) { // Yes, an anti-pattern. But the above dirty hack might die // in weird and unexpected ways, and it shouldn't affect // running a game ever. So hey, let's fly with this... } }
public MyBot(IBotInterface botInterface) : base(botInterface) { }
public LogicCore(IBotInterface handler) { m_bot = handler; }
public TestBot(IBotInterface botInterface) { this.botInterface = botInterface; }
public AngsthaasBot(IBotInterface botProxy) { _botProxy = botProxy; }