Add complete Texas Hold'em poker gameplay including: - Pure function game engine (deck, dealing, betting, showdown) - Hand evaluator supporting all 10 poker hand ranks - Animated card components with 3D flip transitions - CSS Grid oval poker table layout for up to 9 seats - Player seat components with chip tracking and turn indicators - Bet controls with conditional button visibility - Basic AI opponents with random valid action selection - Turn advancement, all-in auto-advance, and dealer rotation Sync delta specs to main specs: poker-table, card-components, game-engine, player-state.
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import type { GameState, BettingRound } from '$lib/types/game-state';
|
|
import type { PlayerSeat } from '$lib/types/player';
|
|
import type { ActionRecord } from '$lib/types/action';
|
|
|
|
export function createInitialState(numPlayers: number, startingStack: number): GameState {
|
|
const players: PlayerSeat[] = [];
|
|
for (let i = 0; i < numPlayers; i++) {
|
|
players.push({
|
|
id: `player-${i}`,
|
|
name: i === 0 ? 'You' : `Bot ${i}`,
|
|
chips: startingStack,
|
|
currentBet: 0,
|
|
status: 'active',
|
|
holeCards: [],
|
|
position: i
|
|
});
|
|
}
|
|
|
|
return {
|
|
deck: [],
|
|
players,
|
|
communityCards: [],
|
|
pot: 0,
|
|
dealerPosition: Math.floor(Math.random() * numPlayers),
|
|
currentTurn: 0,
|
|
bettingRound: 'idle',
|
|
actionHistory: [],
|
|
currentBet: 0,
|
|
lastRaiseAmount: 0,
|
|
smallBlind: 10,
|
|
bigBlind: 20
|
|
};
|
|
}
|
|
|
|
export function rotateDealer(state: GameState): GameState {
|
|
const nextDealer = (state.dealerPosition + 1) % state.players.length;
|
|
return { ...state, dealerPosition: nextDealer };
|
|
}
|
|
|
|
export function recordAction(
|
|
state: GameState,
|
|
playerId: string,
|
|
type: ActionRecord['type'],
|
|
amount?: number
|
|
): GameState {
|
|
return {
|
|
...state,
|
|
actionHistory: [
|
|
...state.actionHistory,
|
|
{ playerId, type, amount, timestamp: Date.now() }
|
|
]
|
|
};
|
|
}
|