コード例 #1
0
        public void RunGameLoop(CancellationToken cancellationToken)
        {
            var gameInfo = _botProxy.Read <GameInfo>();

            _botProxy.Log($"Playing as {gameInfo.Identity}");

            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var state = _botProxy.Read <GameState>();

                _botProxy.Log(Environment.NewLine + CondensedUtf8Formatter.Instance.Format(state));

                Move move = DetermineMove(state);

                _botProxy.Log($"Moving {move.UsedCard}! Run away, run away!!\n");

                _botProxy.Write(move);
            }
        }
コード例 #2
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);
        }