Skip to content

Instantly share code, notes, and snippets.

@LaffinToo
Created December 31, 2011 07:24
Show Gist options
  • Save LaffinToo/1543236 to your computer and use it in GitHub Desktop.
Save LaffinToo/1543236 to your computer and use it in GitHub Desktop.
Tourney Bracket System
<?php
$teams=array('Alpha','Beta','Gamma','Delta','Epsilon','Zeta','Eta');
define('MY_EOL','<br .>'.PHP_EOL);
$round=0;
$participants=$teams;
while(count($participants)>1)
{
$round++; // Increment our round
Echo 'Round '. $round. MY_EOL;
$tables=array(); // Clear our tables
$index=0;
while(count($tables) < floor(count($participants)/2)) // want an even amount of tables
$tables[]=array($participants[$index++],$participants[$index++]);
if($index<count($participants))// extra team, add to tables, but no opposing team
$tables[]=array($participants[$index++],NULL);
$participants=array(); // clear out next round participants
foreach($tables as $idx=>$table)
{
$tbl=$idx+1;
echo " Table #{$tbl}: ";
if($table[1]===NULL) // extra team advances to next level automatically
{
echo "{$table[0]} Holdover";
$winner=0;
} else {
echo "{$table[0]} vs. {$table[1]}";
$winner=rand(0,1); // Generate a winner
}
echo " - Winner {$table[$winner]}". MY_EOL;
$participants[]=$table[$winner]; // Add WInnerto next round
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment