/** * Gets a winning variant. * * @param $salt string * @return mixed */ public function getVariant($salt) { // No chance of winning if ($this->oddsTotal == 0) { return null; } // First variant is a sure winner if (reset($this->variants) >= 100) { return (string) key($this->variants); } // Time to roll $roll = $this->roller->getRoll($salt); foreach ($this->variants as $variant => $odds) { if ($roll < $odds) { return (string) $variant; } } // Loser return null; }
<?php include 'roller.class.php'; $roller = new Roller(); $roller->Roll(); echo $roller->EncodeGrid();
} public function AddToBack() { $TempQuery = array(); for ($i = $this->GroupsAllowed; $i <= $this->lengthOfQuery - 1; $i++) { $TempQuery[] = $this->Query[$i]; } for ($i = 0; $i <= $this->GroupsAllowed - 1; $i++) { $TempQuery[] = $this->Query[$i]; } $this->Query = $TempQuery; } } for ($j = 1; $j <= $TestCases; $j++) { $R = $Tests_R[$j - 1]; $MyRoller = new Roller(); $MyRoller->Query = $Tests_Query[$j]; $MyRoller->k = $Tests_k[$j - 1]; $MyRoller->lengthOfQuery = $Tests_N[$j - 1]; for ($i = 1; $i <= $R; $i++) { $MyRoller->GetNextPeople(); $MyRoller->CalculateMoney(); $MyRoller->AddToBack(); } $OutputString .= "Case #" . $j . ": " . $MyRoller->Money . "\n"; } //echo $OutputString; //exit; $myFile = "output.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $OutputString);