Jump to content

Recommended Posts

 

i have teams which i want to distribute in a schedule , each team play with the others one time and each team play once a day .

i got teams' names and its number from the database.

Q: i want to make daily schedule for matches (like the daily schedule of world cup)

and to enter each date in the database with the schedule of this date.

please follow this link to see what i need:

http://www.teamopolis.com/tools/round-robin-generator.aspx

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/206048-need-help-with-team-scheduling/
Share on other sites

You will have to modify this code to match what you want but this gives you a starting point anyway:

 

<table width=600 align=center>
<tr>
<?php
/*
* This code owes an enormous debt to
* http://www.barrychessclub.org.uk/berger2001.htm
*/
    // Find out how many teams we want fixtures for.
    if (!isset($_GET['teams'])) {
        print get_form();
        exit;
    }
    $teams = $_GET['teams'];
    $weeks = $_GET['weeks'];
    $startdate = $_GET['startdate'];

    // If odd number of teams add a "ghost".
    $ghost = false;
    if ($teams % 2 == 1) {
        $teams++;
        $ghost = true;
    }

    // Generate the fixtures using the cyclic algorithm.
    $totalRounds = $weeks;
    $matchesPerRound = $teams / 2;
    $rounds = array();
    for ($i = 0; $i < $totalRounds; $i++) {
        $rounds[$i] = array();
    }

    for ($round = 0; $round < $totalRounds; $round++) {
        for ($match = 0; $match < $matchesPerRound; $match++) {
            $home = ($round + $match) % ($teams - 1);
            $away = ($teams - 1 - $match + $round) % ($teams - 1);
            // Last team stays in the same place while the others
            // rotate around it.
            if ($match == 0) {
                $away = $teams - 1;
            }
            $rounds[$round][$match] = ($home + 1) . " v " . ($away + 1);
        }
    }

/*   // Interleave so that home and away games are fairly evenly dispersed.
    $interleaved = array();
    for ($i = 0; $i < $totalRounds; $i++) {
        $interleaved[$i] = array();
    }

    $evn = 0;
    $odd = ($teams / 2);
    for ($i = 0; $i < sizeof($rounds); $i++) {
        if ($i % 2 == 0) {
            $interleaved[$i] = $rounds[$evn++];
        } else {
            $interleaved[$i] = $rounds[$odd++];
        }
    }

    $rounds = $interleaved;

    // Last team can't be away for every game so flip them
    // to home on odd rounds.
    for ($round = 0; $round < sizeof($rounds); $round++) {
        if ($round % 2 == 1) {
            $rounds[$round][0] = flip($rounds[$round][0]);
        }
    }    */

    // Display the fixtures
    $matchdate = '';
    for ($i = 0; $i < sizeof($rounds); $i++) {
        print "<p>Round " . ($i + 1) . "</p>\n";
        foreach ($rounds[$i] as $r) {
            if($matchdate == ''){
            $matchdate = $startdate;
            }
            if(strlen($r) == 6){
              $team1 = $r[0];
              $team2 = $r[4].$r[5];
              echo $matchdate."    ".$team1." vs ".$team2."<br>";
            } else {
              $team1 = $r[0];
              $team2 = $r[4];
              echo $matchdate."    ".$team1." vs ".$team2."<br>";
            }
        }
        print "<br />";
        $matchdate = date("Y-m-d", strtotime("$matchdate +1 week"));
    }
    print "<br />";
    if ($ghost) {
        print "Matches against team " . $teams . " are byes.";
    }

?>
</tr>
</table>

 

 

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.