1

I'm making an automatic football league generator and got stuck on schedule. I have an algorithm for generating everything, but not schedule. Take a look:

[tour-id] => Array
    (
        [playing-day] => 2013-03-07
        [tour (tour-id+1)] => 9
        [game-id] => Array
            (
                [blue team-id] => 13
                [red team-id] => 10
            )

For example:

[8] => Array
    (
        [playday] => 2013-03-07
        [tour] => 9
        [0] => Array
            (
                [blue] => 13
                [red] => 10
            )

        [1] => Array
            (
                [red] => 15
                [blue] => 12
            )

        [2] => Array
            (
                [blue] => 6
                [red] => 11
            )

And now when i have got all that data I can just use few foreach() for taking what i need. But - the thing i want is to put teams into RED & BLUE teams normally.

I mean:

  • One team in one side (BLUE or RED) can play maximum 2 times;
  • One team in one round must play $totalTours/2 games in one round.

For example if there are 9 teams, in 1st round a team must play 4 tours in RED (total, not in a row) and 5 tours in BLUE. In 2nd round it must play 5 tours in RED, 4 tours in BLUE.

The algorithm must work even if there are 100 teams.

RBarryYoung
  • 55,398
  • 14
  • 96
  • 137
Darker
  • 83
  • 2
  • 8
  • I feel, that your constrants for rules (One team in one side (BLUE or RED) can play maximum 2 times;) makes impossible to generate schedule for infinite number of teams – zb' Feb 09 '13 at 02:54
  • Thanks for your answer. It must be possible. Look at real football leagues, for example premier league. There are no more than 2 matches in one side in a row. I know it is a bit complicated, working on it for 7 hours and still can't get answer. – Darker Feb 09 '13 at 02:56
  • @eicto only brings up the issue with regards to an infinite number. It should also be noted that the football leagues you are comparing to likely have probably half as many teams. More teams = longer to calculate. – Nuclearman Feb 09 '13 at 08:36
  • @MC it is timewaste to make such generator if it will be impossible to make galactic championship :) – zb' Feb 09 '13 at 08:44
  • @eicto: True, but they probably have massive quantum computers to work with... :) – Nuclearman Feb 09 '13 at 08:47
  • But if one team can play maximum 2 times as one tshirt, it means it can play only 4 times for championship, which decrease hierarcy height, **i understand nothing in football** *so i feel free to proof that it is impossible to play it* – zb' Feb 09 '13 at 08:56
  • Ah, I see what you're getting at, if you look at that way, then it's limited to only 16 teams. However, the OP is actually looking for a method to avoid teams being the same shirt more than twice in a row, not twice total. – Nuclearman Feb 09 '13 at 09:12
  • I think I'll leave it at that, as ignoring that issue, I'm also not familiar enough with football leagues to come up with an algorithm. Although I'll agree with the OP that it should at least be possible. This looks like it should be in P. – Nuclearman Feb 09 '13 at 10:00
  • Are you asking something similar to this question? http://stackoverflow.com/questions/1037057/how-to-automatically-generate-a-sports-league-schedule?rq=1 – Lars Nyström Feb 09 '13 at 11:09

2 Answers2

1

To build a set of fixtures, you need every team to play each other precisely once.

A decent way of doing this is to "rotate" the elements around a single fixed element.

Fixing the number 1, we need to

Round one would be

 1 2 3 4 5 
 v v v v v
10 9 8 7 6

Round two would be

 1 10 2 3 4
 v  v v v v 
 9  8 7 6 5

Round 3 would be

 1 9 10 2 3
 v v  v v v 
 8 7  6 5 4

And so on, until the numbers have rotated all the way around.

I used this approach to build a set of fixtures in JavaScript: https://jsfiddle.net/jonwinstanley/9dfLm8nq/97/

Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116
0

I think you should check the round-robin tournament-Algorithm. In This way you can schedule your Tournament easily and the place will become optional. When Time is reached, you can set the location home or away

Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
Masoud R
  • 102
  • 3
  • 10