Skip to content Skip to sidebar Skip to footer

Python (football Games Algorithm Troubles)

I am trying to write algorithm for football group stage. for example: i have 4 teams in the stage. teams = ['team1', 'team2', 'team3', 'team4'] then i got an all unique pairs imp

Solution 1:

The problem can be seen as an exact cover problem and can be solved like a Sudoku with Algorithm X, of which there are Python implementations available on the web.

The set that needs to be covered consists of:

  • a combination of each team and each match day
  • every match pairing

which for four teams is:

A1, A2, A3, B1, B2, B3, C1, C2, C3, D1, D2, D3, AB, AC, AD, BC, BD, CD

where B3 means team B plays on day 3 and BD means team B plays team D.

The available subsets are all match pairings combined with all match days, which for four teams is:

AB1: A1, B1, ABAB2: A2, B2, ABAB3: A3, B3, ABAC1: A1, C1, AC
...
CD3: C3, D3, CD

Solving this yields a great many possible fixtures, essentially permutations of teams and match days. Pick one, order by match day and play.

There are no solutions if there is an odd number of teams. Add a null team as dummy and don't play the matches where one of the sides is the dummy.

Post a Comment for "Python (football Games Algorithm Troubles)"