Jump to content

creating matches


chriscloyd

Recommended Posts

I'm pretty good with coding but am getting stumphed.

IDEA - Automatch teams

count how many teams are in the teams table

then choose two of them and insert them into the match table

but if they are already in there choose two different numbers and do this till all the teams have been scheduled a match

Link to comment
Share on other sites

The following code will form all possible "rotations" of the teams that are listed in the array -

 

<?php
$teams = array(
        "Team 1",
        "Team 2",
        "Team 3",
        "Team 4",
        "Team 5",
        "Team 6",
        "Team 7",
        "Team 8",
        "Team 9",
        "Team 10"
        );

    $numteams = sizeof($teams);
    $days = array();
    $team_list = array_keys($teams);
    $tmp_list = array_splice($team_list, 1, sizeof($team_list) - 1);
    $count = sizeof($tmp_list) + 1;
    $days = array();
    
    for ($i = 0;$i < $numteams - 1;$i++) {
        $days[$i] = array();
        $day_list = array_merge(array($team_list[0]), $tmp_list);
        for ($j = 0;$j < $count / 2;$j++) {
            $days[$i][] = $teams[$day_list[$j]] . ' vs ' . $teams[$day_list[$count - $j - 1]];
        }
        // rotate $tmp_list
        $elm = array_shift($tmp_list);
        array_push($tmp_list, $elm);
    }
    echo "<pre>";
    print_r($days);
    echo "</pre>";  
?>

Link to comment
Share on other sites

Okay well i dont want to create a match for everyone for example i will run the match creator once a week for each season then when i run it say there is 10 teams

 

the ten teams will be matched to other teams that they have not played

 

questions?

 

please help

Link to comment
Share on other sites

If you don't want any duplicates, you must create all possible combinations at one time at the beginning and then use the groupings that that code produces, one different group per week.

 

If you attempt to do this by random picking, as you get closer and closer to the end, you will find that you cannot match up teams that have not played each other and you will have more and more teams sitting out that week.

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.