public void PlayGame(Bot bot) { List<string> input = new List<string>(); try { while (true) { string line = System.Console.In.ReadLine().Trim().ToLower(); if (line.Equals(READY)) { ParseSetup(input); FinishTurn(); input.Clear(); } else if (line.Equals(GO)) { state.StartNewTurn(); ParseUpdate(input); bot.DoTurn(state); FinishTurn(); input.Clear(); } else if (line.Equals(END)) { bot.OnGameEnd(state); break; } else { input.Add(line); } } } catch (Exception e) { #if DEBUG FileStream fs = new FileStream("debug.log", System.IO.FileMode.Create, System.IO.FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(e); sw.Close(); fs.Close(); #endif } }
public static void PlayGame(Bot bot, TextReader inputTextReader) { List<string> input = new List<string>(); try { while (true) { string line = inputTextReader.ReadLine().Trim().ToLower(); switch (line) { case READY: ParseSetup(input); bot.Init(); input.Clear(); FinishTurn(); break; case GO: ParseUpdate(input); bot.DoTurn(); input.Clear(); FinishTurn(); break; case END: return; default: input.Add(line); break; } } } #if DEBUG catch (Exception e) { StreamWriter sw = File.CreateText("Exception_Debug_" + DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss") + ".log"); sw.WriteLine("Turn Number: " + GameState.CurrentTurnNumber); sw.WriteLine(); sw.WriteLine(e); sw.Close(); } #else catch (Exception) { } #endif }
public static void PlayGame(Bot bot) { PlayGame(bot, Console.In); }
public void PlayGame(Bot bot) { StreamWriter writer = new StreamWriter("botInput.txt",false); List<string> input = new List<string>(); bool endParse = false; while (!endParse) { string line = System.Console.In.ReadLine().Trim().ToLower(); writer.WriteLine(line); writer.Flush(); switch (line) { case READY: ParseSetup(input); bot.Initialise(state); FinishTurn(); input.Clear(); break; case GO: if (!LastState) { state.StartNewTurn(); ParseUpdate(input); bot.DoTurn(state); FinishTurn(); input.Clear(); } else { string[] scores = input[1].Remove(0, 6).Split(); ;//de "scores<spatie>"er af slopen en dan splitten int myScore = int.Parse(scores[0]);//we gaan er vanuit de wij bot 1 zijn bool won = false; for (int i = 1; i < scores.GetLength(0); i++) { won = myScore > int.Parse(scores[i]) && won; } input.RemoveRange(0, 4);//alle informatie voor de laatste state er af slopen ParseUpdate(input); bot.LastTurn(state, won); } break; case END: LastState = true; break; default: input.Add(line); break; } //catch (Exception e) { // #if DEBUG // FileStream fs = new FileStream("debug.log", System.IO.FileMode.Create, System.IO.FileAccess.Write); // StreamWriter sw = new StreamWriter(fs); // sw.WriteLine(e); // sw.Close(); // fs.Close(); // #endif } writer.Close(); }