public override void QualifyClubs() { List <Match> matches = new List <Match>(); if (!twoLegs) { matches = new List <Match>(_matches); } else { for (int i = 0; i < _matches.Count / 2; i++) { matches.Add(_matches[_matches.Count / 2 + i]); } } foreach (Qualification q in _qualifications) { foreach (Match m in matches) { Club c = null; //Winners if (q.ranking == 1) { c = m.Winner; if (!q.isNextYear) { q.tournament.rounds[q.roundId].clubs.Add(c); } else { q.tournament.AddClubForNextYear(c, q.roundId); } } //Losers else if (q.ranking == 2) { c = m.Looser; if (!q.isNextYear) { q.tournament.rounds[q.roundId].clubs.Add(c); } else { q.tournament.AddClubForNextYear(c, q.roundId); } } if (c != null) { if (q.tournament.isChampionship && c.Championship != null) { if (q.tournament.level > c.Championship.level) { c.supporters = (int)(c.supporters / 1.8f); } else if (q.tournament.level < c.Championship.level) { c.supporters = (int)(c.supporters * 1.8f); } } } } } }
public string GenerateArticle(Match match) { string res = ""; Club team1 = match.Winner; Club team2 = match.Looser; float niv1 = team1.Level(); float niv2 = team2.Level(); int score1 = match.score1; int score2 = match.score2; //Winner is favorite if (niv1 - niv2 > 8) { //Large victoire if ((team1 == match.home && score1 - score2 > 2) || (team1 == match.away && score2 - score1 > 2)) { res = _gl_f[Session.Instance.Random(0, _gl_f.Count)]; } //Match nul else if (score1 - score2 == 0) { res = _n_f[Session.Instance.Random(0, _n_f.Count)]; } //Petite victoire else { res = _gs_f[Session.Instance.Random(0, _gs_f.Count)]; } } //Vainqueur est l'outsider else if (niv1 - niv2 < -8) { //Large victoire if ((team1 == match.home && score1 - score2 > 2) || (team1 == match.away && score2 - score1 > 2)) { res = _gl_o[Session.Instance.Random(0, _gl_o.Count)]; } //Match nul else if (score1 - score2 == 0) { res = _n_o[Session.Instance.Random(0, _n_o.Count)]; } //Petite victoire else { res = _gs_o[Session.Instance.Random(0, _gs_o.Count)]; } } //Equilibré else { //Large victoire if ((team1 == match.home && score1 - score2 > 2) || (team1 == match.away && score2 - score1 > 2)) { res = _gl_e[Session.Instance.Random(0, _gl_e.Count)]; } //Match nul else if (score1 - score2 == 0) { res = _n_e[Session.Instance.Random(0, _n_e.Count)]; } //Petite victoire else { res = _gs_e[Session.Instance.Random(0, _gs_e.Count)]; } } res = res.Replace("VAINQUEUR", team1.shortName); res = res.Replace("VAINCU", team2.shortName); res = res.Replace("SCORE", score1 + "-" + score2); return(res); }
public static List <Qualification> AdjustQualificationsToNotPromoteReserves(List <Qualification> initialQualifications, List <Club> ranking, Tournament from) { List <Qualification> qualifications = new List <Qualification>(initialQualifications); for (int i = 0; i < qualifications.Count; i++) { qualifications.Sort(new QualificationComparator()); Qualification q = qualifications[i]; Club concernedClub = ranking[q.ranking - 1]; bool ok = RuleIsRespected(concernedClub, q, from.level); int j = i; if (from.isChampionship) { while (!ok) { int tempValue = qualifications[j].ranking; Qualification first = qualifications[j]; Qualification second = qualifications[j + 1]; first.ranking = qualifications[j + 1].ranking; second.ranking = tempValue; qualifications[j] = first; qualifications[j + 1] = second; ok = RuleIsRespected(concernedClub, qualifications[j], from.level); j++; } } } /* * for (int j = 0; j < qualifications.Count; j++) * { * Qualification q = qualifications[j]; * //If the two tournaments involved are championship and the level of the destination is higher in league structure than the current league * if (from.isChampionship && q.tournament.isChampionship && q.tournament.level < from.level) * { * int offset = 0; * bool pursue = true; * while (pursue && j + offset < qualifications.Count) * { * //This is a reserve club so it must not be promoted * if (ranking[q.ranking - 1 + offset] as ReserveClub != null) * { * offset++; * } * else * { * pursue = false; * //If there is an offset, make a swap * if (offset > 0) * { * Qualification first = qualifications[j]; * Qualification second = qualifications[j + offset]; * int tempRanking = second.ranking; * second.ranking = first.ranking; * first.ranking = tempRanking; * qualifications[j] = second; * qualifications[j + offset] = first; * } * } * } * } * }*/ return(qualifications); }
public static int Difference(List <Match> games, Club c, RankingType rankingType = RankingType.General) { return(Gf(games, c, rankingType) - Ga(games, c, rankingType)); }
public static int Played(List <Match> matchs, Club c, RankingType rankingType = RankingType.General) { return(Wins(matchs, c, rankingType) + Draws(matchs, c, rankingType) + Loses(matchs, c, rankingType)); }
public static int Points(List <Match> matchs, Club c, RankingType rankingType = RankingType.General) { return((3 * Wins(matchs, c, rankingType)) + Draws(matchs, c, rankingType)); }
public void RandomDrawing() { List <Club> pot = new List <Club>(_round.clubs); try { pot.Sort(new ClubComparator(_attribute, false)); if (pot[0] as NationalTeam != null) { List <NationalTeam> nationalsTeams = new List <NationalTeam>(); foreach (Club c in pot) { nationalsTeams.Add(c as NationalTeam); } nationalsTeams.Sort(new NationsFifaRankingComparator(false)); pot.Clear(); foreach (NationalTeam nt in nationalsTeams) { pot.Add(nt); } } } catch { Utils.Debug("Le tri pour " + _round.name + "(" + _round.Tournament.name + " de type niveau a echoué"); } int minTeamsByGroup = _round.clubs.Count / _round.groupsCount; List <Club>[] hats = new List <Club> [minTeamsByGroup]; //Some groups will get one more team if (_round.clubs.Count % _round.groupsCount > 0) { hats = new List <Club> [minTeamsByGroup + 1]; } int ind = 0; for (int i = 0; i < minTeamsByGroup; i++) { hats[i] = new List <Club>(); for (int j = 0; j < _round.groupsCount; j++) { hats[i].Add(pot[ind]); ind++; } } //Create last hat if there is remaining teams if (_round.clubs.Count % _round.groupsCount > 0) { hats[hats.Length - 1] = new List <Club>(); for (int j = _round.groupsCount * minTeamsByGroup; j < _round.clubs.Count; j++) { hats[hats.Length - 1].Add(pot[j]); } } //Foreach groups for (int i = 0; i < _round.groupsCount; i++) { //Foreach hats for (int j = 0; j < hats.Length; j++) { if (hats[j].Count > 0) { Club c; Club drawnClub; //TODO: Change the algorithm to avoid use of securityLoop variable int securityLoop = 0; do { securityLoop++; c = hats[j][Session.Instance.Random(0, hats[j].Count)]; drawnClub = c; //The rule cannot be respected, switch current club with another club in the same hat but already placed if (_round.rules.Contains(Rule.OneClubByCountryInGroup) && ContainsCountry(_round.groups[i], c.Country()) && ContainsOnlyCountry(hats[j], c.Country())) { //For k from 0 to i, see if the k-j switch unlock the situation int k = 0; bool blocked = true; while (blocked) { Club switchClub = _round.groups[k][j]; if ((k + 1) == i || (!ContainsCountry(_round.groups[i], switchClub.Country()) && !ContainsCountry(_round.groups[k], c.Country()))) { blocked = false; if ((k + 1) != i) { _round.groups[k][j] = c; c = switchClub; } } k++; } } //Console.WriteLine(_round.Tournament + " - " + _round.rules.Contains(Rule.OneClubByCountryInGroup) + " - " + ContainsCountry(_round.groups[i], c.Country()) + " - " + !ContainsOnlyCountry(hats[j], c.Country())); }while(securityLoop < 500 && _round.rules.Contains(Rule.OneClubByCountryInGroup) && (ContainsCountry(_round.groups[i], c.Country()) && !ContainsOnlyCountry(hats[j], c.Country()))); if (securityLoop == 500) { Console.WriteLine("Security break used for " + _round.name + " (" + _round.Tournament.name + ")"); } hats[j].Remove(drawnClub); _round.groups[i].Add(c); } } } }