+ let ignoreds = [];
+ let ignored_games = [], ignored_games_expl = [];
+ if (ultimateconfig['kick_fifth_from_third']) {
+ let ignoreds_A = [], ignoreds_B = [], ignoreds_C = [];
+ pick_out_rank(A, 5, ignoreds_A);
+ pick_out_rank(B, 5, ignoreds_B);
+ pick_out_rank(C, 5, ignoreds_C);
+
+ if (ignoreds_A.length >= 2) {
+ ignoreds_A = [ ignoreds_A[ignoreds_A.length - 1] ];
+ }
+ if (ignoreds_B.length >= 2) {
+ ignoreds_B = [ ignoreds_B[ignoreds_B.length - 1] ];
+ }
+ if (ignoreds_C.length >= 2) {
+ ignoreds_C = [ ignoreds_C[ignoreds_C.length - 1] ];
+ }
+ ignoreds = ignoreds_A.concat(ignoreds_B).concat(ignoreds_C);
+
+ // Protect the “candidates” array, so that apply_games_to_teams() further down
+ // doesn't modify it (we want to compare old and new).
+ A = jsonclone(A);
+ B = jsonclone(B);
+ C = jsonclone(C);
+
+ // Recompute scores (but not ranks!) without the ignored games.
+ let games_a = parse_games_from_spreadsheet(response_a, 'Group A', false);
+ apply_games_to_teams(games_a, A, ignoreds, ignored_games);
+ let games_b = parse_games_from_spreadsheet(response_b, 'Group B', false);
+ apply_games_to_teams(games_b, B, ignoreds, ignored_games);
+ let games_c = parse_games_from_spreadsheet(response_c, 'Group C', false);
+ apply_games_to_teams(games_c, C, ignoreds, ignored_games);
+
+ // Filter out ignored games involving the candidate thirds.
+ let candidates_to_idx = make_teams_to_idx(candidates);
+ for (const game of ignored_games) {
+ if (candidates_to_idx[game[0]] !== undefined ||
+ candidates_to_idx[game[1]] !== undefined) {
+ if (game[2]) {
+ ignored_games_expl.push("Ignoring (arbitrarily) " + game[0] + "–" + game[1]);
+ } else {
+ ignored_games_expl.push("Ignoring " + game[0] + "–" + game[1]);
+ }
+ }
+ }
+
+ let new_teams = A.concat(B).concat(C);
+ let new_teams_to_idx = make_teams_to_idx(new_teams);
+
+ // Move back the scores (points, gd, goals).
+ for (let cand of candidates) {
+ let new_version = new_teams[new_teams_to_idx[cand.shortname]];
+ if (cand.pts != new_version.pts ||
+ cand.gd != new_version.gd ||
+ cand.goals != new_version.goals) {
+ cand.pts = new_version.pts;
+ cand.gd = new_version.gd;
+ cand.goals = new_version.goals;
+ ignored_games_expl.push(cand.shortname + " at " + cand.pts + " pts, " + addsign(new_version.gd) + " GD");
+ }
+ }
+ }
+