I have been looking for this solution and there are few docs but couldn't get them correctly. Please have a look. I tried to implement the round robin algorithm to create a match schedule but stack on home away distribution.
$allTeam=[3,10,8,7];
$leng=sizeof($allTeam);
$lastHalf=$leng-1;
for ($t=0; $t <$leng-1 ; $t++) {
for ($i=0; $i < $leng/2; $i++) {
if($t % 2== 0){
\Log::info('Home Team => '.$allTeam[$i].' vs '. $allTeam[$lastHalf-$i].'<=Away Team');
}else{
\Log::info('Away Team =>'.$allTeam[$i].' vs '. $allTeam[$lastHalf-$i].'<= Home Team');
}
}
/*now rotate the array. For this first insert the last item into postion 1*/
array_splice( $allTeam, 1, 0, $allTeam[$leng-1]);
/*now pop up the last element*/
array_pop($allTeam);
}
this is the result
Home Team => 3 vs 7<=Away Team
Home Team => 10 vs 8<=Away Team
Away Team =>3 vs 8<= Home Team
Away Team =>7 vs 10<= Home Team
Home Team => 3 vs 10<=Away Team
Home Team => 8 vs 7<=Away Team
You can see it's not equally distributed. How can I make sure that if one team plays as home team in first round then this team should play away in next round? Similarly if away in first round then home in next round?
Thank you.