Zugzwangle Posted April 23, 2013 Share Posted April 23, 2013 Hi there - thanks in anticipation of any help you may offer!!! I am using the following function, to generate a round robin tournament: function round_robin($teams){ if (count($teams)%2 != 0){ array_push($teams,"Bye"); } $away = array_splice($teams,(count($teams)/2)); $home = $teams; for ($i=0; $i < count($home)+count($away)-1; $i++){ for ($j=0; $j<count($home); $j++){ $round[$i][$j]['Home']=$home[$j]; $round[$i][$j]['Away']=$away[$j]; } if(count($home)+count($away)-1 > 2){ array_unshift($away,array_shift(array_splice($home,1,1))); array_push($home,array_pop($away)); } } return $round; } This produces a round robin tournament, but this does not outcome in evenly distributed data. For example if you insert an array of values 'Team 1', 'Team 2', 'Team 3', 'Team 4', 'Team 5', 'Team 6', it revolves the other teams around 'Team 1' meaning, 'Team 1' gets 6x Home games. I added bit of code to even it up. $unformatted_matches = round_robin($teams_entered); foreach ($unformatted_matches as $key => $value) { if($key % 2 !== 1) { $reversed = array_reverse($value[0]); array_values($reversed); $unformatted_matches[$key][0] = $reversed; } } However the produces a schedule such as shown at this link: https://docs.google.com/spreadsheet/ccc?key=0AvUWywpDuSKudFZId1NUSGltVll6dlVKanluQjhGWmc&usp=sharing where all but 'Team 1' face consecutive matches away or at home!! I hope you are still following at this point! What I would like to achieve, is to make the matches distributed evenly, so each team would play Home Away Home Away etc!! It would be great to get some help here. Thanks Zugz Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 23, 2013 Share Posted April 23, 2013 Why not just check how many home games each team has when you are matching them up and give the home game to whichever team has the fewest? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.