chriscloyd Posted October 8, 2008 Share Posted October 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted October 8, 2008 Author Share Posted October 8, 2008 i did a loop but it just keep choosing the same numbers Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2008 Share Posted October 8, 2008 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>"; ?> Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted October 8, 2008 Author Share Posted October 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted October 8, 2008 Author Share Posted October 8, 2008 maybe i should explian it better team 10 teams and create five matches check to see if teams have been matched up already in previous weeks or see if they are already matches up agasint a different team this week Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2008 Share Posted October 8, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.