@idealic/poker-engine
Version:
Professional poker game engine and hand evaluator with built-in iterator utilities
105 lines (104 loc) • 2.97 kB
JavaScript
/**
* Converts a Game object to PHH format notation in JSON format
* @param game The game object to convert
* @returns A complete PHH game object with all possible fields
*/
export function getCompletePHHFormat(game) {
// Base required fields that exist in all game types
const baseFormat = {
variant: game.variant,
ante_trimming_status: game.anteTrimming ?? false,
antes: game.antes,
blinds_or_straddles: game.blindsOrStraddles,
starting_stacks: game.startingStacks,
actions: game.actions,
// Optional fields from BaseGame
players: game.players,
venue: game.event, // Using event as venue if available
city: game.city,
region: game.region,
country: game.country,
time_control: game.timeLimit
? {
time: game.timeLimit,
increment: 0,
timebank: game.timeBanks?.[0] ?? 0,
}
: undefined,
commentary: undefined, // Not available in Game type
author: game.author,
event: game.event,
day: game.day,
month: game.month,
year: game.year,
hand: game.hand,
finishing_stacks: game.finishingStacks,
// Additional metadata
rake: game.rake,
rake_percentage: game.rakePercentage,
total_pot: game.totalPot,
table: game.table,
level: game.level,
url: game.url,
address: game.address,
postal_code: game.postalCode,
seat_count: game.seatCount,
seats: game.seats,
};
// Add variant-specific fields
if (isNoLimitGame(game)) {
return {
...baseFormat,
min_bet: game.minBet,
bring_in: undefined,
small_bet: undefined,
big_bet: undefined,
};
}
else if (isStudGame(game)) {
return {
...baseFormat,
min_bet: undefined,
bring_in: game.bringIn,
small_bet: game.smallBet,
big_bet: game.bigBet,
};
}
else {
// Fixed limit game
return {
...baseFormat,
min_bet: undefined,
bring_in: undefined,
small_bet: game.smallBet,
big_bet: game.bigBet,
};
}
}
// Type guards for different game variants
function isNoLimitGame(game) {
return ['NT', 'NS', 'PO', 'N2L1D'].includes(game.variant);
}
function isStudGame(game) {
return ['F7S', 'F7S/8', 'FR'].includes(game.variant);
}
// Example usage:
/*
const game: Game = {
variant: 'NT',
antes: [0, 0, 0],
blindsOrStraddles: [50, 100, 0],
startingStacks: [10000, 10000, 10000],
players: ['Player 1', 'Player 2', 'Player 3'],
actions: [
'd dh p1 AhKh',
'd dh p2 ????',
'd db Th9h8h',
'p1 cbr 400',
'p2 f'
],
minBet: 100
};
const phhFormat = getCompletePHHFormat(game);
*/
//# sourceMappingURL=phh.js.map