หลักการทำงานของความยุติธรรมที่พิสูจน์ได้ใน Mines
นี่คือวิธีเล่น Mines บน Cloudbet และวิธีตรวจสอบว่าตำแหน่งกับระเบิดในแต่ละรอบเป็นไปตามหลักความยุติธรรมที่พิสูจน์ได้
วิธีเล่น Mines
ทุกรอบของ Mines บน Cloudbet ใช้พื้นฐานความยุติธรรมที่พิสูจน์ได้แบบเดียวกัน ได้แก่ Server Seed, Client Seed, Nonce และ SHA3-256/SHAKE256 ซึ่งอธิบายไว้อย่างละเอียดในหน้าหลักเรื่องหลักการทำงานของความยุติธรรมที่พิสูจน์ได้ หน้านี้จะกล่าวถึงสิ่งที่เฉพาะเจาะจงกับ Mines คือลำดับตัวเลขสุ่มนั้นกลายเป็นตารางระเบิดที่คุณเล่นด้วยได้อย่างไร
แปลงตัวเลขสุ่มให้กลายเป็นตารางระเบิด
คุณเลือกจำนวนระเบิดที่จะวางตั้งแต่เริ่มเกม เราเรียกจำนวนนี้ว่า N ตาราง Mines ขนาด 5×5 สามารถคลี่ออกเป็นแถวเดียวที่มี 25 ตำแหน่ง แต่ละตำแหน่งมีดัชนีของตัวเอง เริ่มจาก 1:

เราสุ่มตัวเลขจากลำดับตัวเลขสุ่ม (สร้างขึ้นด้วยวิธีเดียวกับที่อธิบายไว้ในหน้าความยุติธรรมที่พิสูจน์ได้) เพื่อกำหนดตำแหน่งของระเบิดลูกแรก:

หากต้องวางระเบิดเพิ่ม เราจะสุ่มตัวเลขอีกครั้งและทำซ้ำ แต่คราวนี้จะเหลือเพียง 24 ตำแหน่งให้เลือก:

กระบวนการนี้จะทำซ้ำจนกว่าจะวางระเบิดครบทุกลูก จากนั้นตารางทั้งหมดจะถูกสร้างขึ้นใหม่และเก็บเป็นความลับจนกว่ารอบจะจบ:

รายละเอียดทางเทคนิค: การเลือกตำแหน่งระเบิดแต่ละลูก
ก่อนการเลือกแต่ละครั้ง เราจะทราบค่า P คือจำนวนตำแหน่งที่ปลอดภัยจากระเบิดที่เหลือให้เลือก โดย P เริ่มต้นที่ 25 และลดลงทีละ 1 ทุกครั้งที่วางระเบิด
ตัวเลขสุ่มขนาด 4 ไบต์ (32 บิต) จะถูกดึงมาจากผลลัพธ์ของ SHAKE256 สำหรับระเบิดแต่ละลูก โดยมีค่าตั้งแต่ 0 ถึง 4,294,967,295 เพื่อเลือกอย่างยุติธรรมในบรรดา P ตำแหน่ง เราใช้วิธี Rejection Sampling (ดูแนวคิดทั่วไปที่อธิบายไว้ในหลักการทำงานของความยุติธรรมที่พิสูจน์ได้) จากนั้นนำผลลัพธ์มา Modulo กับ P เพื่อให้ได้ดัชนีตำแหน่ง:
// Pseudo Code
const placementIndex = randomNumber % P;

หากยังต้องวางระเบิดเพิ่ม ตำแหน่งที่เลือกไปแล้วจะถูกนำออกจากรายการ ค่า P จะลดลง 1 และกระบวนการนี้จะทำซ้ำ
การเล่นเกม
ตารางระเบิดฉบับสมบูรณ์จะถูกสร้างและซ่อนไว้บนเซิร์ฟเวอร์ก่อนที่คุณจะเดินหมากแต่ละครั้ง และไม่สามารถเปลี่ยนแปลงหรือถูกแก้ไขโดยไม่ถูกตรวจจับได้ในภายหลัง เนื่องจาก Commitment ที่แชร์ให้คุณไว้แล้ว ทุกช่องที่คุณเลือกกดจะถูกตรวจสอบกับตารางที่ซ่อนไว้นี้เพียงเท่านั้น
โค้ดสำหรับตรวจสอบผลลัพธ์ด้วยตัวเอง
โปรแกรมนี้ตรงกับการทำงานของ Mines บน Cloudbet ใส่ Server Seed, Client Seed, Nonce และจำนวนระเบิดของคุณ ติดตั้งไลบรารีที่จำเป็นหนึ่งตัว แล้วรันโปรแกรมนี้เพื่อสร้างผลลัพธ์เกมของคุณขึ้นใหม่ด้วยตัวคุณเอง
หมายเหตุ: หากต้องการเปิดเผย Server Seed ของเกมที่จบไปแล้วบน Cloudbet คุณจะต้องเริ่มรอบใหม่ไปแล้วเท่านั้น (ซึ่งจะทำการ Rotate ไปเป็น Seed คู่ใหม่)
ไลบรารีที่จำเป็น:
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 สักรอบ แล้วตรวจสอบผลลัพธ์ด้วยเครื่องมือคำนวณความยุติธรรมที่พิสูจน์ได้ ใช้เวลาเพียงไม่กี่วินาที ไม่ต้องมีความรู้ด้านเทคนิคก็ทำได้
คุณจะได้เห็นกระบวนการทำงานจริง ตรวจสอบ Seed ของคุณ และดูว่าเครื่องมือนี้สร้างผลลัพธ์ของคุณขึ้นใหม่จากศูนย์ได้อย่างไร
