I am using a Round Robin to schedule games. I would like each team to play "n" games, and I have "x" teams. Everything is great if "x" is even, but if "x" is odd I have to add another team, "bye" to get it to work.
When I have 11 teams playing 4 games each, with the byes it works out so that 4 teams are getting byes. This is inefficient, as they could just play each other so that every team plays 4 games.
After scheduling all the games including the games where one team is "bye", I am trying to make all the teams that have had a "bye week" and make them play one game against each other. I need to make sure that the teams haven't played before.
Since I am using a small number of teams, I am just using a randomizer to try combinations until one works. However, I cannot get that to work.
Here is my code that schedules the teams that had by rounds to play one another. I would like to go through and check to see if they have played before, and if they have, randomize the list so that we can try a different combo. I don't think the checking whether or not the teams have played so far is working, as it never shuffles the teams even if they have overlap.
while (true){
$needshuffled = "no";
for ($j=0; $j < $maxgames/2; $j++){
$k = $j*2;
$round[$maxgames][$j]["Home"]=$byeteams[$k];
$round[$maxgames][$j]["Away"]=$byeteams[$k+1];
$home = $round[$maxgames][$j]["Home"];
$away = $round[$maxgames][$j]["Away"];
$sql = "SELECT * FROM `temp`
WHERE (Home = '$home' and Away = '$away')
or (Home = '$away' and Away = '$home')";
if ($conn->query($sql) === TRUE) {
if ($result=mysqli_query($conn,$sql))
{
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
if ($rowcount > 0)
{
$needshuffled = "yes";
}
}
}
}
if ($needshuffled == "no"){
break;
}
}