0, "Triple 1st Bingo" => 0, "Lone Double 1st Bingo" => 0, "Lone Triple 1st Bingo" => 0); $doubleBingo = 0; $tripleBingo = 0; $cards = array(); ?>

A bingo simulation with trials

$maxBingos) { // print out however many we can $numLines = $maxBingos - $startingBingo + 1; } // rough error checking if ($startingBingo < 0 || $startingBingo > $maxBingos || $numLines < 1) { return; } if ($numLines == 1) { echo " \n"; echo " ".$startingBingo."\n"; if ($firstOnly) { echo " ".round($firstBingos[$startingBingo]/$GAMES*100,1)."%\n"; } else { echo " ".round($totalBingos[$startingBingo]/$GAMES*100,1)."%\n"; } echo " \n"; return; } // print out multiple games at a time $tempBingos = 0; if ($firstOnly) { for ($i = 0; $i < $numLines; $i++) { $tempBingos += $firstBingos[$startingBingo + $i]; } } else { for ($i = 0; $i < $numLines; $i++) { $tempBingos += $totalBingos[$startingBingo + $i]; } } echo " \n"; echo " ".$startingBingo." - ".($startingBingo+$numLines-1)."\n"; echo " ".round($tempBingos/$GAMES*100,1)."%\n"; echo " \n"; return; } function printGames ($startingBall, $numGames) { global $bingoBalls; global $b1Ball; global $num_balls; global $GAMES; // if we've requested x games, but less are left if ($startingBall + $numGames - 1 > $num_balls) { // print out however many we can $numGames = $num_balls - $startingBall + 1; } // rough error checking if ($startingBall < 1 || $startingBall > $num_balls || $numGames < 1) { return; } if ($numGames == 1) { echo " \n"; echo " ".$startingBall."\n"; echo " ".$bingoBalls[$startingBall]."\n"; echo " ".round($b1Ball[$startingBall]/$GAMES*100,0)."%\n"; echo " \n"; return; } // print out multiple games at a time $tempBingoBall = 0; $tempB1Ball = 0; for ($i = 0; $i < $numGames; $i++) { $tempBingoBall += $bingoBalls[$startingBall + $i]; $tempB1Ball += $b1Ball[$startingBall + $i]; } // just take the last value since they are cumulative echo " \n"; echo " ".$startingBall." - ".($startingBall+$numGames-1)."\n"; echo " ".$tempBingoBall."\n"; echo " ".round($tempB1Ball/$GAMES*100,0)."%\n"; echo " \n"; return; } function markCards ($b) { global $cards; global $players; global $cardsperplayer; global $num_balls; global $pattern; global $squaresInPattern; global $doubleBingo; global $tripleBingo; // find the correct column $c = floor( ($b-1) / ($num_balls/5) ); $num_bingos = 0; // iterate through all the cards for ($p = 0; $p < $players; $p++) { for ($cpp = 0; $cpp < $cardsperplayer; $cpp++) { for ($r = 0; $r < 5; $r++) { if ($cards[$p][$cpp][$r][$c][0] == $b) { $cards[$p][$cpp][$r][$c][1] = 1; // we just marked a square in the pattern if ($pattern[$r][$c]) { // see if we just got bingo // increment number correct if (++$cards[$p][$cpp]["bingo"] == $squaresInPattern) { $num_bingos++; $cards[$p]["bingo"]++; // see if we have a double or triple bingo if ($cards[$p]["bingo"] == 2) { $doubleBingo++; } if ($cards[$p]["bingo"] == 3) { // don't double count double bingos $doubleBingo--; $tripleBingo++; } } } } } } } return $num_bingos; } function printCards () { global $cards; for ($p = 0; $p < count($cards); $p++) { echo "Player ".$p.":
\n"; for ($cpp = 0; $cpp < count($cards[0]); $cpp++) { echo "Card ".$cpp.":
\n"; for ($r = 0; $r < 5; $r++) { for ($c = 0; $c < 5; $c++) { // just a shorthand; pass by reference to avoid copying lots of data $n = &$cards[$p][$cpp][$r][$c]; if ($n[1]) { echo "(". ($n[0]<10 ? "0" : "") . $cards[$p][$cpp][$r][$c][0].") "; } else { echo ($n[0]<10 ? "0" : "") . $cards[$p][$cpp][$r][$c][0]." "; } } echo "
\n"; } echo "
\n"; } } } function setupCards () { global $cards; global $players; global $cardsperplayer; global $num_balls; $cards = array(); // setup the cards for ($p = 0; $p < $players; $p++) { // everyone starts with zero bingos $cards[$p]["bingo"] = 0; for ($cpp = 0; $cpp < $cardsperplayer; $cpp++) { // everyone starts with 1 square marked $cards[$p][$cpp]["bingo"] = 1; for ($c = 0; $c < 5; $c++) { // setup the possible numbers to choose $colChoices = array(); for ($i = $num_balls/5*$c + 1; $i <= $num_balls/5 * ($c+1); $i++) { $colChoices[] = $i; } for ($r = 0; $r < 5; $r++) { // need to do the splice to ensure unique numbers $tempNum = array_splice($colChoices, array_rand($colChoices), 1); // value of the number $cards[$p][$cpp][$r][$c][0] = $tempNum[0]; // if it's the center, it starts marked $cards[$p][$cpp][$r][$c][1] = ($r == 2 && $c == 2 ? 1 : 0); } } } } } function resetCards () { global $cards; global $players; global $cardsperplayer; global $num_balls; // setup the cards for ($p = 0; $p < $players; $p++) { // everyone starts with zero bingos $cards[$p]["bingo"] = 0; for ($cpp = 0; $cpp < $cardsperplayer; $cpp++) { // everyone starts with 1 square marked $cards[$p][$cpp]["bingo"] = 1; for ($r = 0; $r < 5; $r++) { for ($c = 0; $c < 5; $c++) { // is it marked or not? $cards[$p][$cpp][$r][$c][1] = ($r == 2 && $c == 2 ? 1 : 0); } } } } } setupCards(); for ($g = 0; $g < $GAMES; $g++) { shuffleBalls(); //resetCards(); setupCards(); $doubleBingo = 0; $tripleBingo = 0; $noBingosThisGame = 1; $ballsDrawn = 0; $num_bingos = 0; $bingoBallNumber = $num_balls + $extraballs; // while there are balls left while ($ballsDrawn < $num_balls && ($ballsDrawn < $specificballs || ($specificballs == 0 && $ballsDrawn < $bingoBallNumber + $extraballs) ) ) { $ballsDrawn++; $b = drawBall(); $num_bingos += markCards($b); // first bingos if ($num_bingos && $noBingosThisGame) { $bingoBalls[$ballsDrawn]++; $bingoBallNumber = $ballsDrawn; $noBingosThisGame = 0; // record how many first bingos we got $firstBingos[$num_bingos]++; // track additional stats $firstBingoStats["Double 1st Bingo"] += $doubleBingo; $firstBingoStats["Triple 1st Bingo"] += $tripleBingo; if ($num_bingos == 2 && $doubleBingo == 1) { $firstBingoStats["Lone Double 1st Bingo"]++; } elseif ($num_bingos == 3 && $tripleBingo == 1) { $firstBingoStats["Lone Triple 1st Bingo"]++; } // update actualMaxFirstBingos $actualMaxFirstBingos = max($num_bingos, $actualMaxFirstBingos); } if ($b == 1) { $b1Ball[$ballsDrawn]++; } } // while // after the game ends, note how many bingos there were $totalBingos[$num_bingos]++; // update actualMaxBingos $actualMaxBingos = max($num_bingos, $actualMaxBingos); // update bingosPerPlayer for ($p = 0; $p < $players; $p++) { $bingosPerPlayer[ $cards[$p]["bingo"] ]++; } } // for each game // Calculate the average number of balls needed to get the first bingo $averageBingoBall = 0; for ($i = 1; $i <= $num_balls; $i++) { $averageBingoBall += $bingoBalls[$i] * $i; } $averageBingoBall /= $GAMES; // Calculate the average number of bingos per game $averageBingos = 0; for ($i = 0; $i <= $maxBingos; $i++) { $averageBingos += $totalBingos[$i] * $i; } $averageBingos /= $GAMES; // Calculate the average number of bingos per player $averageBingosPerPlayer = 0; for ($i = 1; $i <= $cardsperplayer; $i++) { $averageBingosPerPlayer += $bingosPerPlayer[$i] * $i; } $averageBingosPerPlayer /= $players; $averageBingosPerPlayer /= $GAMES; // Calculate how often B1 didn't appear $noB1Ball = $GAMES; for ($i = 1; $i < count($b1Ball); $i++) { $noB1Ball -= $b1Ball[$i]; } ?> The average number of balls required to get at least 1 bingo matching the pattern in the room is 0.
The average number of bingos per game is 0.
The average number of bingos per player is 0.
The B1 Ball did not appear in 0% of the games played.

Balls Drawn 1st Bingo B1 Ball
\n"; echo " \n"; echo " \n"; echo " \n"; } ?>
Bingos per
Player
Frequency
".$b."".round($bingosPerPlayer[$b]/$GAMES/$players*100,0)."%

Bingos
per Game
Frequency

# of 1st
Bingos
Frequency

$value) { ?>

Balls in hopper:
Extra balls to draw 
after 1st bingo:
Total balls to draw 
(non-zero overrides extra balls)
Players in room:
Cards per player:
Pattern: \n"; for ($col = 0; $col < 5; $col++) { $k = $pattern[$row][$col]; // the middle space is always marked if ($row == 2 && $col == 2) { echo " \n"; echo " \n"; } else { ?> \n"; } ?>
X
Trials:
Balls to print together:
(left table)
Bingos to print together:
(middle bottom table)