示例#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);
 }
示例#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";
}
示例#3
0
 $eachDot = ceil($durationInSeconds / ($screenCols - 3));
 /*
 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) {