}
<?php
//Case Battle Fairness | Round Validation
$serverSeed = 'cef7544d66f612a41121f506a2903135'; // Server seed
$eosBlockSeed = '1a869e974688d612eae6886a5813c2d67da069f3be2b3bf23d381cf2705c9dab'; // EOS Block Seed
// Update this to true if you are validating a tiebreaker result.
$isTiebreaker = false;
/*
* Case Ticket's Quantity, by default it's 100,000
* We only change this if there's a case that has different ticket distribution.
* Right now, all cases use 100,000 by default.
* IMPORTANT: If it's the tiebreaker round, this will be number of players participating on the tiebreaker.
* For example, if two players are participating on a tiebreaker the ticketQuantity is 2.
*/
$ticketQuantity = 100000;
/* ------------------ */
if ($serverSeed == '' || $eosBlockSeed == '') {
echo "Fill in details";
return;
}
define('MAX_HEX_SEGMENTS', 6);
define('HEX_SEGMENT_SIZE', 2);
define('BASE_FOR_HEX_CONVERSION', 256);
define('HASH_TYPE', 'sha256');
if (!function_exists('calculateDecimalValue')) {
function calculateDecimalValue(string $preResult): float
{
$decimalValue = 0;
for ($i = 0; $i < MAX_HEX_SEGMENTS; $i++) {
$hexValue = substr($preResult, HEX_SEGMENT_SIZE * $i, HEX_SEGMENT_SIZE);
$decimalValue += hexdec($hexValue) / pow(BASE_FOR_HEX_CONVERSION, $i + 1);
}
return $decimalValue;
}
}
if (!function_exists('getProvablyFairResult')) {
function getProvablyFairResult(string $init, string $serverSeed, int $qty): array
{
$preResult = hash_hmac(HASH_TYPE, $init, $serverSeed);
$decimalValue = calculateDecimalValue($preResult);
$result = (int) ($decimalValue * $qty) + 1;
return [
'preResult' => $preResult,
'result' => $result,
];
}
}
$serverSeed = preg_replace("/\r|\n/", "", $serverSeed);
$eosBlockSeed = preg_replace("/\r|\n/", "", $eosBlockSeed);
// Print header
echo "Case Battle Fairness Validation Results\n";
echo "=====================================\n";
echo "Server Seed: " . substr($serverSeed, 0, 16) . "...\n";
echo "EOS Block Seed: " . substr($eosBlockSeed, 0, 32) . "...\n";
echo "Ticket Quantity: " . number_format($ticketQuantity) . "\n\n";
// Create table header
echo str_pad("Round", 7) . " | ";
for ($player = 1; $player <= 4; $player++) {
echo str_pad("Player $player", 12) . " | ";
}
echo "\n";
echo str_repeat("-", 7) . " | " . str_repeat(str_repeat("-", 12) . " | ", 4) . "\n";
// Calculate and display results for all rounds and players
for ($roundNumber = 1; $roundNumber <= 50; $roundNumber++) {
echo str_pad($roundNumber, 7, " ", STR_PAD_LEFT) . " | ";
for ($playerPosition = 1; $playerPosition <= 4; $playerPosition++) {
if ($isTiebreaker) {
$stringToHash = "$eosBlockSeed-$roundNumber";
} else {
$stringToHash = "$eosBlockSeed-$roundNumber-$playerPosition";
}
$result = getProvablyFairResult($stringToHash, $serverSeed, $ticketQuantity);
echo str_pad(number_format($result['result']), 12, " ", STR_PAD_LEFT) . " | ";
}
echo "\n";
// Add a separator line every 10 rounds for better readability
if ($roundNumber % 10 == 0 && $roundNumber < 50) {
echo str_repeat("-", 7) . " | " . str_repeat(str_repeat("-", 12) . " | ", 4) . "\n";
}
}
echo "\n\nNote: Each result represents the ticket number (1 to " . number_format($ticketQuantity) . ") that won for that player in that round.\n";
// Optional: Show example of hash calculation for verification
echo "\n\nExample Verification (Round 1, Player 1):\n";
echo "==========================================\n";
$exampleString = "$eosBlockSeed-1-1";
$exampleResult = getProvablyFairResult($exampleString, $serverSeed, $ticketQuantity);
echo "Input String: " . substr($exampleString, 0, 50) . "...\n";
echo "HMAC-SHA256 Hash: " . $exampleResult['preResult'] . "\n";
echo "Result: " . number_format($exampleResult['result']) . "\n";
?>
preferences:
30.05 ms | 414 KiB | 5 Q