xcore-betkit
v0.0.12
Published
XCore Betting Kit
Downloads
24
Readme
XCore BetKit
A TypeScript library that provides WebAssembly-based casino game logic, optimized for web applications.
Features
- 🎮 Game Logic: Implements casino game rules and calculations in WebAssembly
- 🚀 Performance: Uses WebAssembly for high-performance computations
- 📐 Type Safety: Full TypeScript support with accurate type definitions
- 🔌 Simple API: Clean, intuitive API for game operations
- 🧩 Modular Design: Focused components for different games and operations
Installation
npm install xcore-betkitUsage
Basic Setup
import XCoreBetKit from 'xcore-betkit';
// Configure and initialize the library
XCoreBetKit.configure({
wasmPath: './assets/betkit.wasm'
});
// Load the WebAssembly module asynchronously
await XCoreBetKit.asyncLoad();
// Now you can use the libraryBaccarat Example
// Define a hand for Baccarat
const hand = {
p1: { number: 10, color: 1 }, // King of Hearts (value 0)
p2: { number: 9, color: 2 }, // 9 of Diamonds (value 9)
b1: { number: 6, color: 3 }, // 6 of Clubs (value 6)
b2: { number: 2, color: 4 }, // 2 of Spades (value 2)
p3: { number: 0, color: 0 }, // No card
b3: { number: 0, color: 0 } // No card
};
// Determine the result of a hand
const result = await XCoreBetKit.baccarat.determineResult(hand);
console.log(`Result index: ${result.data}`);
// Get the detailed result information
const resultInfo = await XCoreBetKit.baccarat.idxToResultInfo(result.data);
console.log(`Winner: ${resultInfo.data.win}`);Roadmaps Example
// Array of game result indices (from determineResult calls)
const resultIndices = [1, 2, 0, 1, 1, 0, 2];
// Generate roadmaps data
const roadmapsData = await XCoreBetKit.baccarat.roadmaps(resultIndices);
// Access the various roadmap types
console.log(roadmapsData.data.bigroad); // Main Big Road
console.log(roadmapsData.data.bigeyeboy); // Big Eye Boy Road
console.log(roadmapsData.data.smallroad); // Small Road
console.log(roadmapsData.data.cockroach); // Cockroach Road
// Access statistics
console.log(`Banker wins: ${roadmapsData.data.statistics.banker}`);
console.log(`Player wins: ${roadmapsData.data.statistics.player}`);
console.log(`Ties: ${roadmapsData.data.statistics.tie}`);API Reference
Configuration
XCoreBetKit.configure(options: {
wasmPath: string; // Path to the WebAssembly module
debug?: boolean; // Enable debug logging (default: false)
logLevel?: LogLevel; // Set logging level (default: INFO)
scriptTimeout?: number; // Timeout for script loading (default: 30000ms)
onProgress?: (status: string) => void; // Progress callback
});Loading
// Asynchronously load the WebAssembly module
await XCoreBetKit.asyncLoad();
// Check if the module is loaded
const isLoaded = XCoreBetKit.isLoaded();
// Force reload of the module
await XCoreBetKit.forceReload();
// Get environment information
const envInfo = XCoreBetKit.getEnvironmentInfo();Baccarat Module
The Baccarat module provides the following methods:
// Determine the result of a hand (returns result index)
const result = await XCoreBetKit.baccarat.determineResult(hand);
// Rank a baccarat hand (returns numeric rank)
const rank = await XCoreBetKit.baccarat.rankHand(hand);
// Convert index to hand
const unrankedHand = await XCoreBetKit.baccarat.unrankHand(index);
// Check if player or banker can draw
const drawPossibilities = await XCoreBetKit.baccarat.canDraw(hand);
// Convert index to result info
const resultInfo = await XCoreBetKit.baccarat.idxToResultInfo(index);
// Convert result info to index
const resultIndex = await XCoreBetKit.baccarat.resultInfoToIdx(resultInfo);
// Get card information and metadata
const cardsInfo = await XCoreBetKit.baccarat.cardsInfo();
// Generate roadmaps from game results
const roadmaps = await XCoreBetKit.baccarat.roadmaps(resultIndices);Data Types
// Card object
interface Card {
number: number; // 1-13 (Ace=1, Jack=11, Queen=12, King=13)
color: number; // 1-4 (Hearts=1, Diamonds=2, Clubs=3, Spades=4)
}
// Baccarat hand
interface BaccaratHands {
p1: Card; // Player card 1
p2: Card; // Player card 2
p3: Card; // Player card 3 (if drawn)
b1: Card; // Banker card 1
b2: Card; // Banker card 2
b3: Card; // Banker card 3 (if drawn)
}
// Result info
interface BaccaratResultInfo {
index: number; // Result index
win: "banker" | "player" | "tie"; // Winner
banker_natural: boolean; // Banker has natural
player_natural: boolean; // Player has natural
player_dragon_bonus_count: number; // Player dragon bonus point count
banker_dragon_bonus_count: number; // Banker dragon bonus point count
perfect_pair: boolean; // Perfect pair occurred
banker_dragon_bonus: boolean; // Banker dragon bonus
super6: boolean; // Super 6 occurred
super6_count: number; // Super 6 count
size: "small" | "big"; // Size
player_pair: boolean; // Player pair
player_dragon_bonus: boolean; // Player dragon bonus
banker_pair: boolean; // Banker pair
any_pair: boolean; // Any pair
}
// Draw possibilities
interface DrawPossibilities {
player: boolean; // Player can draw
banker: boolean; // Banker can draw
}
// Response format
interface WasmResponse<T> {
code: number; // 0 for success, non-zero for error
message: string; // Success or error message
data: T; // Response data
}
// Roadmaps data
interface BaccaratRoadmaps {
history: number[]; // History of game results
bigroad: number[][]; // Big Road data
bigeyeboy: number[][]; // Big Eye Boy Road data
smallroad: number[][]; // Small Road data
cockroach: number[][]; // Cockroach Road data
prediction: BaccaratPrediction; // Predictions
statistics: BaccaratStatistics; // Game statistics
threeroad: number[][]; // Three Road data
}Browser Support
XCore BetKit supports all modern browsers with WebAssembly capabilities:
- Chrome 57+
- Firefox 53+
- Safari 11+
- Edge 16+
