public static List <JudgeRound> ParseJudges(string text, string fighter1Name, string fighter2Name) { List <JudgeRound> ret = new List <JudgeRound>(); string[] split = Regex.Split(text, RegexConstants.Judge, RegexOptions.Multiline); for (int i = 1; i < split.Length; i++) { MatchCollection ties = Regex.Matches(split[i], RegexConstants.JudgeTie, RegexOptions.Multiline); foreach (Match m in ties) { ret.Add(GetJudgeRound(i, m)); } string exp = String.Format(RegexConstants.JudgeWin, Regex.Escape(fighter1Name), Regex.Escape(fighter2Name), RegexOptions.Multiline); MatchCollection winRounds = Regex.Matches(split[i], exp, RegexOptions.Multiline); foreach (Match m in winRounds) { JudgeRound j = (GetJudgeRound(i, m)); if (m.Groups["winner"].Value != fighter1Name) { int score1 = j.Score.Fighter1Score; j.Score.Fighter1Score = j.Score.Fighter2Score; j.Score.Fighter2Score = score1; } ret.Add(j); } } ret = ret.OrderBy(r => r.JudgeNumber).ThenBy(r => r.RoundNumber).ToList(); return(ret); }
private static JudgeRound GetJudgeRound(int i, Match m) { int score1 = Convert.ToInt32(m.Groups["score1"].Value); int score2 = Convert.ToInt32(m.Groups["score2"].Value); int round = Convert.ToInt32(m.Groups["round"].Value); JudgeRound j = new JudgeRound(i, score1, score2, round); return(j); }