private void dopairs(string[] selectedfiles, string strarch, string extension) { allcombats.Clear(); teamNames.Clear(); teamWarriors.Clear(); rounds.Clear(); teams.Clear(); ncombat = 0; fullCombatLog = ""; generator = new RoundRobinPairingsGenerator(); generator.Reset(); int n = 0; foreach (string s in selectedfiles) { var team = new TournamentTeam(n, 0); teams.Add(team); string tmp = Path.GetFileName(selectedfiles[n]); teamNames.Add(n, tmp.Substring(0, tmp.IndexOf(extension))); teamWarriors.Add(n, selectedfiles[n]); n++; } while (true) { TournamentRound round = null; generator.Reset(); generator.LoadState(teams, rounds); round = generator.CreateNextRound(null); if (round != null) { rounds.Add(round); } else { break; } } foreach (TournamentRound round in rounds) { foreach (var pairing in round.Pairings) { allcombats.Add(pairing); } } string memoria = getemptymemory(); string salida = ""; salida = "Tournament arch: " + strarch + "\nTotal Warriors loaded " + selectedfiles.Count().ToString(); if (selectedfiles.Count() < 2) { salida += "\nCannot begin Tournament with only one Warrior!"; } else { salida += "\nPress 'start' button to begin Tournament."; } string envio = "{\"player1\":{\"regs\":\" \",\"code\":\" \",\"name\":\"Player - 1\"},\"player2\":{\"regs\":\" \",\"code\":\" \",\"name\":\"Player - 2\"},\"memory\":[" + memoria + "],\"console\":\"" + salida + "\",\"status\":\"Warriors Loaded.\",\"scores\":\" \"}"; SendDrawEvent(envio.Replace("\n", "\\n").Replace("\r", "")); }
public void RoundRobinHandlesManyCompetitorsWell() { IPairingsGenerator pg = new RoundRobinPairingsGenerator(); List <TournamentTeam> teams = new List <TournamentTeam>(CreateTeams(30)); List <TournamentRound> rounds = new List <TournamentRound>(); try { RunTournament(pg, teams, rounds, true, null); DisplayTournamentRounds(rounds); DisplayTournamentRankings(pg.GenerateRankings()); } catch (InvalidTournamentStateException) { Assert.Fail(); } }
public void RoundRobinCreatesThreeRoundsForThreeCompetitors() { IPairingsGenerator rrpg = new RoundRobinPairingsGenerator(); List <TournamentTeam> teams = new List <TournamentTeam>(CreateTeams(3)); try { List <TournamentRound> rounds = new List <TournamentRound>(); rounds.AddRange(RounRobinBuildAllPairings(teams, rrpg)); Assert.AreEqual(3, rounds.Count); DisplayTournamentRounds(rounds); } catch (InvalidTournamentStateException) { Assert.Fail(); } }
public void RoundRobinTieForSecond() { IPairingsGenerator rrpg = new RoundRobinPairingsGenerator(); List <TournamentTeam> teams = new List <TournamentTeam>(CreateTeams(3)); try { List <TournamentRound> rounds = new List <TournamentRound>(); rounds.AddRange(RounRobinBuildAllPairings(teams, rrpg)); Assert.AreEqual(3, rounds.Count); rounds[0].Pairings[0].TeamScores[0].Score = new HighestPointsScore(1.0d); // A: Win rounds[0].Pairings[0].TeamScores[1].Score = new HighestPointsScore(0.0d); // B: Loss rounds[1].Pairings[0].TeamScores[0].Score = new HighestPointsScore(1.0d); // A: Win rounds[1].Pairings[0].TeamScores[1].Score = new HighestPointsScore(0.0d); // C: Loss rounds[2].Pairings[0].TeamScores[0].Score = new HighestPointsScore(0.5d); // B: Draw rounds[2].Pairings[0].TeamScores[1].Score = new HighestPointsScore(0.5d); // C: Draw DisplayTournamentRounds(rounds); rrpg.LoadState(teams, rounds); List <TournamentRanking> rankings = new List <TournamentRanking>(rrpg.GenerateRankings()); DisplayTournamentRankings(rankings); Assert.AreEqual(3, rankings.Count); Assert.AreEqual(1, rankings[0].Rank); Assert.AreEqual(2, rankings[1].Rank); Assert.AreEqual(2, rankings[2].Rank); } catch (InvalidTournamentStateException) { Assert.Fail(); } }
public void RoundRobinThrowsExceptionOnNullParameters() { IPairingsGenerator rrpg = new RoundRobinPairingsGenerator(); IPairingsGeneratorThrowsExceptionOnNullParameters(rrpg); }