Jump to content

Round Robin Equal Distribution


Zugzwangle

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.