Minesにおけるプロバブリーフェアの仕組み
CloudbetでのMinesの遊び方と、各ラウンドの地雷配置がプロバブリーフェアであることを確認する方法をご紹介します。
Minesの遊び方
CloudbetのすべてのMinesラウンドは、サーバーシード、クライアントシード、ノンス、SHA3-256/SHAKE256という同じプロバブリーフェアの基盤を使用しています——詳しくは当社のプロバブリーフェアの仕組みに関するハブページをご覧ください。このページでは、Mines特有の部分——その乱数列がどのようにして実際にプレイする地雷グリッドになるのか——を解説します。
乱数から地雷グリッドへの変換
ゲーム開始時に配置する地雷の数を選択します——この数をNと呼びます。5×5のMinesグリッドは、それぞれ1から始まるインデックスを持つ25マスの1列に展開できます。

乱数列(プロバブリーフェアページで説明されているのと同じ方法で生成)から数値を1つサンプリングし、最初の地雷の位置を決定します。

さらに地雷を配置する必要がある場合は、別の乱数を引いて同じ処理を繰り返しますが、今回は残り24マスの中から選択します。

これをすべての地雷が配置されるまで繰り返します。完成したグリッドはそのまま再構築され、ラウンドが終了するまで非公開のまま保持されます。

技術的な詳細:各地雷位置の選定
各選定の前に、Pという値——地雷のない残りマス数——がわかります。Pは25から始まり、地雷が1つ配置されるたびに1ずつ減っていきます。
地雷ごとに、SHAKE256の出力から0から4,294,967,295の範囲の4バイト(32ビット)の乱数が引かれます。P個の位置から公正に1つを選ぶため、リジェクションサンプリングを適用し(一般的な考え方はプロバブリーフェアの仕組みで解説しています)、その結果をPで割った余りを配置インデックスとします。
// Pseudo Code
const placementIndex = randomNumber % P;

まだ地雷が残っている場合は、選ばれた位置がリストから除外され、Pが1減り、この処理が繰り返されます。
ゲームプレイ
最終的な地雷入りのグリッドは、プレイヤーが操作を行う前にサーバー上で構築・非公開化されます——すでに共有されているコミットメントのおかげで、その後は気づかれずに変更・改ざんすることはできません。選択した各マスは、この非公開のグリッドと単純に照合されます。
独自検証のためのコード
このプログラムはCloudbetのMines実装に忠実なものです。サーバーシード、クライアントシード、ノンス、地雷の数を入力し、唯一の依存パッケージをインストールしてご自身で実行すれば、ゲームの結果を再構築できます。
注:Cloudbetで完了したゲームのサーバーシードを公開するには、すでに新しいラウンドを開始している(=新しいシードペアにローテーションしている)必要があります。
依存関係:
npm install js-sha3
コード:
// If you are running this yourself, then you can input your own data here
// You can then compare:
// 1) Cloudbet's provided Commitment to the Commitment outputted here. This proves that the Server Seed was not altered during gameplay.
// 2) Cloudbet's provided game outcome to the game outcome outputted here. This proves that your game's outcome was determined solely by the pre-game seeds and was not altered afterwards.
let myServerSeed = 'your_server_seed'; // ✍️YOUR_INPUT✍️: Enter your (unhashed) Server Seed here
let myClientSeed = 'your_client_seed'; // ✍️YOUR_INPUT✍️: Enter your Client Seed here
let myNonce = 1; // ✍️YOUR_INPUT✍️: Enter your Nonce here
let myNumberOfMines = 3; // ✍️YOUR_INPUT✍️: Enter your number of mines here
const usingCustomData = false; // Change this to true if you are using your own data
// Load libraries
const crypto = require('crypto');
const { sha3_256, shake256 } = require('js-sha3');
// Step 1: Generate a Server Seed and Commitment
// And generate a Client Seed - either by player input or by the player's browser
function generateServerSeed() {
let seed = crypto.randomBytes(32).toString('hex');
if (usingCustomData) { seed = myServerSeed; }
const commitment = sha3_256(seed);
return { 'serverSeed': seed, 'commitment': commitment };
}
function getClientSeed() {
let seed = crypto.randomBytes(32).toString('hex');
if (usingCustomData) { seed = myClientSeed; }
return seed;
}
// Step 2: Create a Round Signature with SHA3 using a Server Seed, Client Seed, and Nonce
function createRoundSignature(serverSeed, clientSeed, nonce) {
return sha3_256(`${serverSeed}:${clientSeed}:${nonce}`);
}
// Step 3: Create a SHAKE256 stream generator from a Round Signature.
// To simplify this example program, this function doesn't create a stream, but instead a sequence of custom length.
function* createRandomNumberSequence(numbersToGenerate, roundSignature) {
const numOfBytes = 4 * numbersToGenerate; // 4 bytes (32 bits) per random number we generate
const byteStream = shake256.create(8 * numOfBytes); // shaker256 takes bits as input
byteStream.update(roundSignature); // Use the Round Signature to seed the generator
const buf = Buffer.from(byteStream.digest()); // The Buffer class lets us package every 4 bytes into one 32-bit integer
for (let i = 0; i < numbersToGenerate; i++) {
yield buf.readUInt32BE(i * 4); // Read buf in 4-byte steps
}
throw new Error("No more numbers in the random number sequence! Fix: make 'numbersToGenerate' larger.");
}
// Step 4: Generate the mine locations
function pickUniquePositions(mineCount, totalTiles, rng) {
const available = Array.from({ length: totalTiles }, (_, i) => i);
let result = [];
for (let i = 0; i < mineCount; ++i) {
const index = sample(available.length, rng);
result.push(available[index]);
available.splice(index, 1); // Remove chosen position from list of available positions
}
result.sort((a, b) => a - b); // Sort the mine positions from smallest to largest
result = result.map(num => num + 1); // Increment positions by one so that they start with 1, 2, 3, ...
return result;
}
// Rejection sampling for fair results
function sample(P, rng) {
const maxAcceptable = Math.floor(0x100000000 / P) * P;
// Rejection sampling
let rand;
do {
rand = rng.next().value;
} while (rand >= maxAcceptable);
// Modulo operation
const sampled_number = rand % P;
return sampled_number;
}
// Example usage
(function main() {
const gridSize = 25;
let mineCount = 3;
let nonce = 1;
if (usingCustomData) { mineCount = myNumberOfMines; nonce = myNonce; }
const { serverSeed, commitment } = generateServerSeed();
const clientSeed = getClientSeed();
const roundSignature = createRoundSignature(serverSeed, clientSeed, nonce);
const numbersToGenerate = 24 * 2; // There are max. 24 mines, however due to rejection sampling we may need more random numbers
const rng = createRandomNumberSequence(numbersToGenerate, roundSignature);
const minePositions = pickUniquePositions(mineCount, gridSize, rng);
console.log('📝 Commitment (shown before the game):', commitment);
console.log('🔒 Server Seed (revealed after the game):', serverSeed);
console.log('🎲 Client Seed:', clientSeed);
console.log('🔢 Nonce:', nonce);
console.log('🔁 Round Signature (can be verified after the game):', roundSignature);
console.log('💣 Mine Positions (1 = top-left square, 5 = top-right square, 25 = bottom-right square):', minePositions);
})();
今すぐ試してみる:Minesで運試し
実際に体験してみたいですか? Cloudbet Minesをプレイし、プロバブリーフェア計算機で結果を検証してみましょう。数秒で完了し、専門的な知識は一切必要ありません。
実際のプロセスを目の当たりにし、ご自身のシードを確認しながら、ツールがどのように結果をゼロから再構築するかをご覧いただけます。
