Created
December 31, 2011 07:24
-
-
Save LaffinToo/1543236 to your computer and use it in GitHub Desktop.
Tourney Bracket System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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