if (isset($_POST['makeschedule'])) { // How many meetings.. singel,double or more? //$meetings = $_POST['meetings']; $meetings = 1; $week = 0; $ghost = ""; //----------------------------------------------------------------------------- // Count the number of teams //$n = count($teams); $players = $_POST['players']; $n = $players; // If number of team is odd, add a ghost-team... if ($n %2 != 0) { $n++; $ghost = $n;} // Number of rounds $rounds = ($n-1) * $meetings; // Loop the rounds... for ($r = 1; $r <= $rounds ; $r++) { echo "ROUND ".$r."
";
$matches = "";
if ($r % ($_POST['weeks'] + 1) == 0) {
$week = 1;
} else {
$week++;
}
// For each round loop teams / 2 ... it takes 2 to tango...
for ($s = 1; $s <= $n / 2; $s++) {
// algorithm to take each team "backwards"
$hometeam = ($s==1)? 1 : (($r+$s-2) % ($n-1) +2);
// algorithm to prevent home and awayteam to be the same
$awayteam = ($n - 1 + $r - $s) % ($n -1) +2 ;
// let the venue change after each round... homegame... then awaygame..
if ($r %2) {
$swap = $hometeam;
$hometeam = $awayteam;
$awayteam = $swap;
}
// never print the ghost-team..
if (($hometeam != $ghost) && ($awayteam != $ghost)) {
echo "Player ".$hometeam." vs Player ". $awayteam."
";
}
}
echo "
"; } } echo "
"; ?>