コード例 #1
0
        public static Message Read(this IBotInterface bot)
        {
            if (bot == null)
            {
                throw new ArgumentNullException(nameof(bot));
            }

            var data = bot.ReadLine();

            return(JsonConvert.DeserializeObject <Message>(data));
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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...
            }
        }
コード例 #6
0
 public MyBot(IBotInterface botInterface) : base(botInterface)
 {
 }
コード例 #7
0
 public LogicCore(IBotInterface handler)
 {
     m_bot = handler;
 }
コード例 #8
0
 public TestBot(IBotInterface botInterface)
 {
     this.botInterface = botInterface;
 }
コード例 #9
0
 public AngsthaasBot(IBotInterface botProxy)
 {
     _botProxy = botProxy;
 }