wildboy211 Posted November 5, 2008 Share Posted November 5, 2008 Im glad i found this place, i was looking for a website just like this, youll definitly see me around...anyways, here my question, im trying to make a script that will schedule softball games for me with the following conditions: This league has 32 teams. 6 diamonds 4 games per diamond Each team must play two games every other week. Each team must play the same number or games No duplicate match-ups. Must work with even or odd number of teams. Must work with any number of diamonds. Attached is the script so far...but it only goes to week 4...anyone have any suggestions? [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/131473-huh-i-like-it-herenow-my-question/ Share on other sites More sharing options...
wildboy211 Posted November 6, 2008 Author Share Posted November 6, 2008 okay...im stumped...for some reason this wont work: <html> <head> <style>body{font:10pt Tahoma;}</style> <body> <?php $teams = 32; $weeks = 8; $diamonds = 6; $diamond_slots = 4; $i=1; $j=1; $week=1; $d=1; //create arrays for diamonds e.g. diamond_slot1[0]=>diamond# [1]=>number of slots used while ($d <= $diamonds): $d_slot = "diamond_slot".$d; $$d_slot = array($d, 0); $d++; endwhile; print "Week ".$week.":<br>"; print "<b>Diamond - Slot - Team1 - Team2</b><br>"; while ($j <= 24){ $diamond_rnd = rand(1,$diamonds); $diamond_slot_rnd = rand(1,$diamond_slots); $d_slot = "diamond_slot".$diamond_rnd; //check for slots over 4 //WHY WONT THIS CATCH ANYTHING OVER 4??? // *************************************** while((${$d_slot}[1]) > $diamond_slots){ $diamond_rnd = rand(1,$diamonds); $diamond_slot_rnd = rand(1,$diamond_slots); $d_slot = "diamond_slot".$diamond_rnd; } // randomize teams & check to make sure they arent the same. $team1_rnd = rand(1,$teams); $team2_rnd = rand(1,$teams); while ($team1_rnd == $team2_rnd){ $team1_rnd = rand(1,$teams); $team2_rnd = rand(1,$teams); } // insert random numbers into array $game2 = "game".$j; if (is_array(${$game2}) == FALSE){ $game = "game".$j; $$game = array($diamond_rnd, $diamond_slot_rnd, $team1_rnd, $team2_rnd); print_r(${$game}); print $j."<br>"; $d_slot = "diamond_slot".$diamond_rnd; ${$d_slot}[1] = ${$d_slot}[1] + 1; $j++; }else{ // check to see if theres an identical array $result = array_diff_assoc($newarr,${$game2}); if (count($result)>0): $j++; print "nothing"; elseif(count($result==0)): $game = "game".$j; $$game = array($diamond_rnd, $diamond_slot_rnd, $team1_rnd, $team2_rnd); print_r(${$game}); print $j."<br>"; $d_slot = "diamond_slot".$diamond_rnd; ${$d_slot}[1] = ${$d_slot}[1] + 1; $j++; endif; } } ?> Link to comment https://forums.phpfreaks.com/topic/131473-huh-i-like-it-herenow-my-question/#findComment-683475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.