コード例 #1
0
        /// <summary>Reads the instructions from the reader.</summary>
        public static IEnumerable <Instruction> Read(TextReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                var instruction = Instruction.Empty;
#if !DEBUG
                try
                {
#endif
                instruction = Instruction.Parse(line);
#if !DEBUG
            }
            catch (Exception x)
            {
                Console.WriteLine(x);
            }
#endif
                if (!instruction.IsEmpty())
                {
                    yield return(instruction);
                }
            }
        }
コード例 #2
0
        /// <summary>Runs it all.</summary>
        public void DoRun(IBot bot)
        {
            if (bot == null)
            {
                throw new ArgumentNullException("bot");
            }

            var settings = new Settings();
            var match    = new GameState(settings);

            string line;

            while ((line = this.Reader.ReadLine()) != null)
            {
#if !DEBUG
                try
                {
#endif
                var instruction = Instruction.Parse(line);

                switch (instruction.InstructionType)
                {
                case InstructionType.Player:
                    match.UpdatePlayer(instruction);
                    HandleOpponentReaction(bot, match, instruction);
                    if (match.Result != RoundResult.NoResult)
                    {
                        bot.Result(match);
                    }
                    break;

                case InstructionType.Match: match.UpdateMatch(instruction); break;

                case InstructionType.Settings:
                    settings.Update(instruction);
                    match.Update(settings);
                    break;

                case InstructionType.Action:
                    match.UpdateAction(instruction);
                    var action = bot.Action(match);
                    Writer.WriteLine(action);
                    break;

                case InstructionType.None:
                case InstructionType.Output:
                default:
                    break;
                }
#if !DEBUG
            }
            catch (Exception x)
            {
                Console.Error.WriteLine(line);
                Console.Error.WriteLine(x);
            }
#endif
            }
        }
コード例 #3
0
        /// <summary>Creates an instruction.</summary>
        public static Instruction Create(InstructionType type, string action, object value)
        {
            var line = String.Format("{0} {1} {2}", type, action, value);

            return(Instruction.Parse(line));
        }