/// <summary>Runs it all.</summary>
		public void DoRun(IBot bot, IEnumerable<IInstruction> instructions)
		{
			if (bot == null) { throw new ArgumentNullException("bot"); }
			if (instructions == null) { throw new ArgumentNullException("instructions"); }

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

			foreach (var instruction in instructions)
			{
				if (settings.Apply(instruction))
				{
					bot.ApplySettings(settings);
				}
				else if (state.Apply(instruction)) { }
				else if (instruction is RequestMoveInstruction)
				{
					bot.Update(state);
					try
					{
						var response = bot.GetResponse(((RequestMoveInstruction)instruction).Time);
						Writer.WriteLine(response.Move);
						if (!String.IsNullOrEmpty(response.Log))
						{
							Logger.WriteLine(response.Log);
						}
					}
					catch (Exception x)
					{
						Writer.WriteLine(new MoveInstruction(Move.Center));
						Logger.WriteLine(x);
					}
				}
			}
		}
        /// <summary>Runs it all.</summary>
        public void DoRun(IBot bot, IEnumerable <IInstruction> instructions)
        {
            if (bot == null)
            {
                throw new ArgumentNullException("bot");
            }
            if (instructions == null)
            {
                throw new ArgumentNullException("instructions");
            }

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

            foreach (var instruction in instructions)
            {
                if (settings.Apply(instruction))
                {
                    bot.ApplySettings(settings);
                }
                else if (state.Apply(instruction))
                {
                }
                else if (instruction is RequestMoveInstruction)
                {
                    bot.Update(state);
#if !DEBUG
                    try
                    {
#endif
                    var response = bot.GetResponse(((RequestMoveInstruction)instruction).Time);
                    Writer.WriteLine(response.Move);
                    if (!String.IsNullOrEmpty(response.Log))
                    {
                        Logger.WriteLine(response.Log);
                    }
#if !DEBUG
                }
                catch (Exception x)
                {
                    Writer.WriteLine(MoveInstruction.NoMoves);
                    Logger.WriteLine(x);
                }
#endif
                }
            }
        }
예제 #3
0
        /// <summary>Runs it all.</summary>
        public void DoRun(IBot bot, IEnumerable <IInstruction> instructions)
        {
            if (bot == null)
            {
                throw new ArgumentNullException("bot");
            }
            if (instructions == null)
            {
                throw new ArgumentNullException("instructions");
            }

            var settings = new Settings();
            var matches  = new Matches();

            foreach (var instruction in instructions)
            {
                if (settings.Apply(instruction))
                {
                    bot.ApplySettings(settings);
                }
                else if (matches.Apply(instruction))
                {
                }
                else if (instruction is WinsInstruction)
                {
                    bot.Update((WinsInstruction)instruction);
                }
                else if (instruction is RequestMoveInstruction)
                {
                    bot.Update(matches);
                    try
                    {
                        var response = bot.GetResponse(((RequestMoveInstruction)instruction).Time);
                        Writer.WriteLine(response.Action);
                        if (!String.IsNullOrEmpty(response.Log))
                        {
                            Logger.WriteLine(response.Log);
                        }
                    }
                    catch (Exception x)
                    {
                        Writer.WriteLine(GameAction.Check);
                        Logger.WriteLine(x);
                    }
                }
            }
        }