A tile drawing simulation with trials

$decksize + 1) { // print out however many we can $numlines = $decksize - $startingCard + 1; } // rough error checking if ($startingCard < 0 || $startingCard > $decksize || $numlines < 1) { return; } if ($numlines == 1) { $sumWinners += $winners[$startingCard]; echo " \n"; echo " ".$startingCard."\n"; echo " ".$winners[$startingCard]."\n"; echo " ".$sumWinners."\n"; echo " \n"; return; } // print out multiple games at a time $tempGames = 0; for ($i = 0; $i < $numlines; $i++) { $tempGames += $winners[$startingCard + $i]; } $sumWinners += $tempGames; echo " \n"; echo " ".$startingCard." - ".($startingCard+$numlines-1)."\n"; echo " ".$tempGames."\n"; echo " ".$sumWinners."\n"; echo " \n"; return; } function printActiveTurns ($turn) { global $activeturnwinners; global $numtodraw; global $numplayers; // rough error checking if ($turn < 0 || $turn > $numtodraw) { return; } echo " \n"; echo " ".$turn."\n"; for ($p = 1; $p <= $numplayers; $p++) { echo " ".$activeturnwinners[$p][$turn]."\n"; } echo " \n"; return; } for ($g = 0; $g < $GAMES; $g++) { shuffleDeck(); $numfound = 0; $numdrawn = 0; $currentplayer = 0; $firstalienfound = 0; $currentactiveturns = array_pad(array(), $numplayers+1, 0); // while we haven't drawn enough cards yet and // there are cards left in the deck, keep searching while ($numdrawn++ < $numtodraw && count($deck) > 0) { if (++$currentplayer > $numplayers) { $currentplayer = 1; } $card = dealCard(); switch($card) { // 1 is a target card case 1: $numfound++; if (!$firstalienfound) { $firstalienfound = 1; } else { $activeturns[] = $currentactiveturns; $currentactiveturns = array_pad(array(), $numplayers+1, 0); } $currentactiveturns[$currentplayer]++; break; // didn't find anything special default: if ($firstalienfound) { $currentactiveturns[$currentplayer]++; } break; } // switch } // while if ($firstalienfound) { $activeturns[] = $currentactiveturns; } // how many target cards did I find? $winners[$numfound]++; } // for each game // Calculate the average number of target cards found $averageWinner = 0; for ($i = 1; $i <= $decksize; $i++) { $averageWinner += $winners[$i] * $i; } $averageWinner /= $GAMES; $averageactiveturns = array_pad(array(), $numplayers+1, 0); $activeturnwinners = array(); for ($p = 1; $p <= $numplayers; $p++) { $activeturnwinners[$p] = array_pad(array(), $numtodraw+1, 0); } for ($i = 0; $i < count($activeturns); $i++) { for ($p = 1; $p <= $numplayers; $p++) { // for each active turn count add it so we can average later $averageactiveturns[$p] += $activeturns[$i][$p]; // also track it for display later $activeturnwinners[$p][$activeturns[$i][$p]]++; } } for ($p = 1; $p <= $numplayers; $p++) { $averageactiveturns[$p] /= count($activeturns); } ?> The average number of target tiles found in draws is 0. Average number of active alien turns per player is as follows:
\n"; } ?>

Target Tiles Found Games Sum
\n"; } ?>
Active Turns Player ".$p."
Number of tiles in deck:
Number of target tiles:
Number of players:
Number of tiles to draw:
Number of trials:
Number of lines to print together: