/// <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 } }
/// <summary>Runs it all.</summary> public void DoRun(IBot bot, IEnumerable <Instruction> instructions) { if (bot == null) { throw new ArgumentNullException("bot"); } if (instructions == null) { throw new ArgumentNullException("instructions"); } var settings = new Settings(); var state = new GameState(settings); foreach (var instruction in instructions) { var previous = state.Copy(); HandleOpponentReaction(bot, previous, instruction); state.Update(instruction); switch (instruction.InstructionType) { case InstructionType.Settings: settings.Update(instruction); state.Update(settings); break; case InstructionType.Player: if (state.Result != RoundResult.NoResult) { bot.Result(state); } break; case InstructionType.Action: var action = bot.Action(state); Writer.WriteLine(action); break; case InstructionType.Match: case InstructionType.Output: case InstructionType.None: default: break; } } }