Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $time = microtime(true);
- // codeteil start
- function battle($numPlayers = 20)
- {
- for($x = 1; $x <= $numPlayers; $x++)
- $listPlayers[] = $x;
- shuffle($listPlayers);
- $listRounds = array();
- $numPlayersHalf = $numPlayers * 0.5;
- $count = 0;
- for($round = 1; $round <= $numPlayersHalf; $round++) {
- for($x = $count; $x < $numPlayersHalf; $x++) {
- $listRounds[$round][] = array($listPlayers[$x], null);
- }
- for($x = 0; $x < $count; $x++) {
- $listRounds[$round][] = array($listPlayers[$x], null);
- }
- $a = 0;
- for($x = $numPlayersHalf + $count; $x < $numPlayers; $x++) {
- $listRounds[$round][$a++][1] = $listPlayers[$x];
- }
- $a = $numPlayersHalf - $count;
- for($x = $numPlayersHalf; $x < $numPlayersHalf + $count; $x++) {
- $listRounds[$round][$a++][1] = $listPlayers[$x];
- }
- $count++;
- }
- return $listRounds;
- }
- $listRounds = battle(20);
- // codeteil ende
- echo '<table border="1">';
- echo '<tr>';
- echo '<td></td>';
- for($x = 0; $x < $numPlayers * 0.5; $x++) {
- echo '<td><strong>Spielbrett ' . $x . '</strong></td>';
- }
- echo '</tr>';
- foreach($listRounds AS $round => $fields) {
- echo '<tr>';
- echo '<td><strong>Runde ' . $round . '</strong></td>';
- foreach($fields AS $players) {
- echo '<td>Spieler ' . $players[0] . ' vs. Spieler ' . $players[1] . '</td>';
- }
- echo '</tr>';
- }
- echo '</table>';
- echo '<p style="text-align: center;">' . (microtime(true) - $time) . ' Sek.</p>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement