/// <summary> /// Read expected incoming information. /// </summary> public void Run() { string line; while ((line = Console.ReadLine()) != null) { if (line.Length == 0) { continue; } var parts = line.Split(' '); if (parts[0].Equals("pick_starting_region")) //pick which regions you want to start with { _currentState.SetPickableStartingRegions(parts); var startingRegion = _bot.GetStartingRegion(_currentState, long.Parse(parts[1])); Console.Out.WriteLine(startingRegion.Id); } else if (parts.Length == 3 && parts[0].Equals("go")) { //we need to do a move var output = string.Empty; if (parts[1].Equals("place_armies")) { //place armies var placeArmiesMoves = _bot.GetPlaceArmiesMoves(_currentState, long.Parse(parts[2])); foreach (var move in placeArmiesMoves) { output += move.ToString() + ","; } } else if (parts[1].Equals("attack/transfer")) { //attack/transfer var attackTransferMoves = _bot.GetAttackTransferMoves(_currentState, long.Parse(parts[2])); foreach (var move in attackTransferMoves) { output += move.ToString() + ","; } } if (output.Length > 0) { Console.Out.WriteLine(output); } else { Console.Out.WriteLine("No moves"); } } else if (parts[0].Equals("settings")) { //update settings _currentState.UpdateSettings(parts[1], parts); } else if (parts[0].Equals("setup_map")) { //initial full map is given _currentState.SetupMap(parts); } else if (parts[0].Equals("update_map")) { //all visible regions are given _currentState.UpdateMap(parts); } else if (parts[0].Equals("opponent_moves")) { //all visible opponent moves are given _currentState.ReadOpponentMoves(parts); } else { Console.Error.WriteLine("Unable to parse line \"{0}\"", line); } } }
public void Run() { while (true) { var line = Console.ReadLine(); if (line == null) { break; } line = line.Trim(); if (line.Length == 0) { continue; } String[] parts = line.Split(' '); if (parts[0] == "pick_starting_regions") { // Pick which regions you want to start with currentState.SetPickableStartingRegions(parts); var preferredStartingRegions = bot.GetPreferredStartingRegions(currentState, long.Parse(parts[1])); var output = new StringBuilder(); foreach (var region in preferredStartingRegions) { output.Append(region.Id + " "); } Console.WriteLine(output); } else if (parts.Length == 3 && parts[0] == "go") { // We need to do a move var output = new StringBuilder(); if (parts[1] == "place_armies") { // Place armies List <PlaceArmiesMove> placeArmiesMoves = bot.GetPlaceArmiesMoves(currentState, long.Parse(parts[2])); foreach (var move in placeArmiesMoves) { move.Commit(); output.Append(move.String + ","); } } else if (parts[1] == "attack/transfer") { // attack/transfer var attackTransferMoves = bot.GetAttackTransferMoves(currentState, long.Parse(parts[2])); foreach (var move in attackTransferMoves) { output.Append(move.String + ","); } } if (output.Length > 0) { Console.WriteLine(output); } else { Console.WriteLine("No moves"); } } else if (parts.Length == 3 && parts[0] == "settings") { // Update settings currentState.UpdateSettings(parts[1], parts[2]); } else if (parts[0] == "setup_map") { // Initial full map is given currentState.SetupMap(parts); } else if (parts[0] == "update_map") { // All visible regions are given currentState.UpdateMap(parts); } else if (parts[0] == "opponent_moves") { // All visible opponent moves are given currentState.ReadOpponentMoves(parts); } else { Console.Error.WriteLine("Unable to parse line \"" + line + "\""); } } }