/// <summary> /// Parses a list of the opponent's moves every round. /// Clears it at the start, so only the moves of this round are stored. /// </summary> /// <param name="moveInput"></param> public void ReadOpponentMoves(string[] moveInput) { OpponentMoves.Clear(); for (var i = 1; i < moveInput.Length; i++) { try { Move move; if (moveInput[i + 1].Equals("place_armies")) { var region = VisibleMap.GetRegion(int.Parse(moveInput[i + 2])); var playerName = moveInput[i]; var armies = int.Parse(moveInput[i + 3]); move = new PlaceArmiesMove(playerName, region, armies); i += 3; } else if (moveInput[i + 1].Equals("attack/transfer")) { var fromRegion = VisibleMap.GetRegion(int.Parse(moveInput[i + 2])); if (fromRegion == null) { //might happen if the region isn't visible fromRegion = FullMap.GetRegion(int.Parse(moveInput[i + 2])); } var toRegion = VisibleMap.GetRegion(int.Parse(moveInput[i + 3])); if (toRegion == null) { //might happen if the region isn't visible toRegion = FullMap.GetRegion(int.Parse(moveInput[i + 3])); } var playerName = moveInput[i]; var armies = int.Parse(moveInput[i + 4]); move = new AttackTransferMove(playerName, fromRegion, toRegion, armies); i += 4; } else { //never happens continue; } OpponentMoves.Add(move); } catch (Exception e) { Console.Error.WriteLine("Unable to parse Opponent moves " + e.Message); } } }
// Parses a list of the opponent's moves every round. // Clears it at the start, so only the moves of this round are stored. public void ReadOpponentMoves(String[] moveInput) { opponentMoves.Clear(); for (int i = 1; i < moveInput.Length; i++) { try { Move move; if (moveInput[i + 1] == "place_armies") { Region region = visibleMap.GetRegion(int.Parse(moveInput[i + 2])); String playerName = moveInput[i]; int armies = int.Parse(moveInput[i + 3]); move = new PlaceArmiesMove(playerName, region, armies); i += 3; } else if (moveInput[i + 1] == "attack/transfer") { Region fromRegion = visibleMap.GetRegion(int.Parse(moveInput[i + 2])); if (fromRegion == null) // Might happen if the region isn't visible { fromRegion = fullMap.GetRegion(int.Parse(moveInput[i + 2])); } Region toRegion = visibleMap.GetRegion(int.Parse(moveInput[i + 3])); if (toRegion == null) // Might happen if the region isn't visible { toRegion = fullMap.GetRegion(int.Parse(moveInput[i + 3])); } String playerName = moveInput[i]; int armies = int.Parse(moveInput[i + 4]); move = new AttackTransferMove(playerName, fromRegion, toRegion, armies); i += 4; } else { // Never happens continue; } opponentMoves.Add(move); } catch (Exception e) { Console.Error.WriteLine("Unable to parse Opponent moves " + e); } } }