public function testExpectedLowFixedOdds() { $dist = new FixedOddsDistribution(); $dist->setOdds(0.01); $player = new Player(); $player->setDistribution($dist); $player->setMaxWins(1000); $wins = 0; for ($plays = 0; $plays < 1000; $plays++) { if ($player->isWinner()) { $wins++; } } $this->assertRoughlyEqual($plays * 0.01, $wins, $plays); }
/** * Load the current # of plays (either winning or losing) */ $todayPlayCountFile = 'play-count.' . date('Ymd') . '.txt'; if (!file_exists($todayPlayCountFile)) { // charge the play counts with 100 plays so the EvenOverTimeDistribution // doesn't think a lot of time has passed in the day with no plays, which // would cause a lot of wins to be given out all at once file_put_contents($todayPlayCountFile, "100"); } $curPlays = (int) file_get_contents($todayPlayCountFile); /** * Setup the distribution, time period and player */ $player = new Player(); $player->setMaxWins($winsPerDay); $player->setCurWins($curWins); $player->setPlayCount($curPlays); $timePeriod = new TimePeriod(); $timePeriod->setStartTimestamp($midnightToday); $timePeriod->setEndTimestamp($midnightTomorrow); $timePeriod->setCurrentTimestamp(time()); $player->setTimePeriod($timePeriod); $player->setDistribution(new EvenOverTimeDistribution()); /** * Execute a single instant-win play attempt */ $win = $player->isWinner(); $curPlays++; file_put_contents($todayPlayCountFile, $curPlays); if ($win) {
use InstantWin\Distribution\FixedOddsDistribution; $dist = new FixedOddsDistribution(); $dist->setOdds(0.002); $player = new Player(); $player->setDistribution($dist); $player->setMaxWins(3); */ $dist = new EvenOverTimeDistribution(); $timePeriod = new TimePeriod(); $timePeriod->setStartTimestamp(1); $timePeriod->setEndTimestamp($durationInSeconds); $player = new Player(); $player->setDistribution($dist); $player->setCurWins(0); $player->setMaxWins(3); $player->setTimePeriod($timePeriod); $wins = 0; $plays = 0; for ($curTime = 0; $curTime <= $durationInSeconds; $curTime++) { $timePeriod->setCurrentTimestamp($curTime); $player->setPlayCount($curTime); $win = $player->isWinner(); if ($win) { $wins++; $player->setCurWins($wins); printWin($wins); } else { if ($curTime % $eachDot == 0) { printLossDot(); }