Quote:
Originally Posted by Fou-Lu
Right, which is what the combinations will do for you.
If you run that with 8 teams (which is successful), it will specify 4x teams over 7 weeks, and won't accommodate anything over 7 weeks. Which is expected. If you used 12 (and the script wasn't fubard), it would specify 6 games for 11 weeks.
So scheduling a combination without repeating a team per week is mostly trivial to do. Specifying missing days or overages require a custom ruleset to deal with them. If I specified 3 teams total, then there would be 3 games in total to deal with every combination. That would be 1 game per week for 3 weeks. So what would happen with the other 7 weeks?
|
Fou Check this out
Just in case anybody out there is also looking to do something like this, its not done its
probably not even the best way to it, but it works, as I said earlier its not that complex as
it appears, note the teams and start times, it will take whatever number of teams and
start times and do a schedule for you just pass it the number of weeks and it does the
rest.
I'd appropriate, any advice on improving or styling this better
PHP Code:
// If you wind up with odd number teams, simply add bye as shown.
$teams = array('Team 1','Team 2','Team 3','Team 4','Team 5','team6','team7','bye');
$season = 'Spring 13';
$league = 'Boys';
$date = '2013-02-03';// Schedule start date
$times = array('9am','11am','1pm','3pm');
$date_bits = explode('-',$date);
$start_day = mktime(0, 0, 0, $date_bits[1], $date_bits[2], $date_bits[0]);
$weeks = 10;
$count = count($teams);
$times = array_slice($times,0,floor($count/2));
$times_count = count($times);
$start = 1;
if($count%2!=0)
{
$teams[] = 'Bye';
$count++;
}
$date_i = 0;
for($i=0;$i<$weeks;$i++)
{
$keyA = $start;
$keyB = $keyA-1; if($keyB<1)$keyB = $count-1;
$tA = array();
$tB = array();
for($k=0;$k<$count-1;$k++)
{
$tA[] = $teams[$keyA];
$tB[] = $teams[$keyB];
$keyA++; if($keyA>$count-1) $keyA = 1;
$keyB--; if($keyB<1) $keyB = $count-1;
}
array_unshift($tA,$teams[0]);
$tB[] = $teams[0];
$inc = 0; // time increment
for($k=0;$k<$count;$k++)
{
if($tA[$k]=='Bye'||$tB[$k]=='Bye') continue;
$col = array();
$col['season'] = $season; //season
$col['league'] = $league; //league
$col['Week'] = 'Week '.($i+1); //Week
$col['date'] = date('Y-m-d',strtotime("+{$i} week",$start_day)); //date
$col['time'] = $times[$inc]; //time
$col['teamA'] = $tA[$k]; //result_teamA
$col['_result'] = 'vs';
//$col['teamA_result'] = '0'; //result_teamA
$col['teamB'] = $tB[$k]; //result_teamB
// $col['teamB_result'] = 0;
$data['results'][] = $col;
$inc++;
if($inc==$times_count) break;
}
$start--; if($start<1) $start = $count-1;
// shift allocated times
$first = $times[0];
$times = array_slice($times,1,count($times));
array_push($times,$first);
}
echo '<div align=center><table width=700 border="1">';
foreach($data['results'] as $result)
{
echo '<tr><td align=center nowrap>'.implode('</td><td align=center nowrap>',array_values($result)).'</td></tr>';
}
echo '</table>';