Beispiel #1
0
 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);
 }
Beispiel #2
0
    // 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) {
    echo "You Won!!!\n";
    $curWins++;
    file_put_contents($todayWinCountFile, $curWins);
} else {
    echo "Sorry, you did not win.\n";
}