pelita icon indicating copy to clipboard operation
pelita copied to clipboard

RF: Improve matchplan in round robin-tournament

Open Debilski opened this issue 2 years ago • 1 comments

This commit optimises the matchplan in the round-robin tournament, making it fairer and (hopefully) more fun:

a) At any point each team should have a similar number of played games b) No team should play two games directly after another;

both of these points should make the tournament more interesting to follow.

Finally, in the interest of fairness: c) Blue and red teams (ie. who starts the match) should be assigned evenly.

As having five teams is the usual case during ASPP student tournaments, we special-case this one and implement the circle method in all other cases.

Further motivation:

There are 10 games to be played in a single round-robin tournament with 5 teams, which means that there are 10! = 3628800 possible arrangements (ignoring blue/red difference). Some of then are obviously pathologically bad, such as for example, permutation number 766415:

[(0, 3), (0, 2), (0, 1), (0, 4), (1, 4), (2, 4), (3, 4), (2, 3), (1, 3), (1, 2)]

This game won’t be much fun for teams 0, 4 and 3, and we should probably strive to distribute the teams more evenly across the plan.

Out of these 3628800 permutations, there are only 240 match plans left that don’t have a team play two matches back-to-back [*]:

[(0, 1), (2, 3), (0, 4), (1, 2), (3, 4), (0, 2), (1, 3), (2, 4), (0, 3), (1, 4)]
[(0, 1), (2, 3), (0, 4), (1, 2), (3, 4), (0, 2), (1, 4), (0, 3), (2, 4), (1, 3)]
[(0, 1), (2, 3), (0, 4), (1, 3), (2, 4), (0, 3), (1, 2), (3, 4), (0, 2), (1, 4)]
[(0, 1), (2, 3), (0, 4), (1, 3), (2, 4), (0, 3), (1, 4), (0, 2), (3, 4), (1, 2)]
[(0, 1), (2, 3), (1, 4), (0, 2), (3, 4), (1, 2), (0, 3), (2, 4), (1, 3), (0, 4)]
[(0, 1), (2, 3), (1, 4), (0, 2), (3, 4), (1, 2), (0, 4), (1, 3), (2, 4), (0, 3)]
[(0, 1), (2, 3), (1, 4), (0, 3), (2, 4), (1, 3), (0, 2), (3, 4), (1, 2), (0, 4)]
...

If we allow ourselves to randomly assign the teams to these match plans, then only two arrangements remain:

[{0, 1}, {2, 3}, {0, 4}, {1, 2}, {3, 4}, {0, 2}, {1, 3}, {2, 4}, {0, 3}, {1, 4}]
[{0, 1}, {2, 3}, {0, 4}, {1, 2}, {3, 4}, {0, 2}, {1, 4}, {0, 3}, {2, 4}, {1, 3}]

These are now taken as the basis for the tournament. (I couldn’t find an algorithm that generates these so they are hard-coded for now.)

[*]: As an aside: all these match plans have one team play in both the first and the final match, meaning it is impossible to have this feature when playing multiple rounds with five teams without reassigning the teams to new positions each round.

Closes: #736

Debilski avatar May 07 '22 22:05 Debilski

Codecov Report

Merging #742 (c679c31) into main (0ceec92) will increase coverage by 0.32%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #742      +/-   ##
==========================================
+ Coverage   85.33%   85.65%   +0.32%     
==========================================
  Files          21       21              
  Lines        2291     2343      +52     
==========================================
+ Hits         1955     2007      +52     
  Misses        336      336              
Impacted Files Coverage Δ
pelita/tournament/__init__.py 72.54% <ø> (ø)
pelita/tournament/roundrobin.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0ceec92...c679c31. Read the comment docs.

codecov-commenter avatar May 07 '22 22:05 codecov-commenter