feat: blackjack split

This commit is contained in:
milo
2025-10-20 18:48:08 +02:00
parent 59bbca5c00
commit b2df6a5b49
3 changed files with 17 additions and 15 deletions

View File

@@ -314,10 +314,10 @@ export function checkAutoSolve(gameState) {
return true;
}
export async function autoSolveMoves(gameState) {
export function autoSolveMoves(userId, gameState) {
const moves = [];
const foundations = gameState.foundationPiles;
const tableau = gameState.tableauPiles;
const foundations = JSON.parse(JSON.stringify(gameState.foundationPiles));
const tableau = JSON.parse(JSON.stringify(gameState.tableauPiles));
function canMoveToFoundation(card) {
let foundationPile = foundations.find(pile => pile[pile.length - 1]?.suit === card.suit);
@@ -352,17 +352,17 @@ export async function autoSolveMoves(gameState) {
sourceCardIndex: column.length - 1,
sourcePileIndex: i,
sourcePileType: 'tableauPiles',
userId: gameState.userId,
userId: userId,
}
moveCard(gameState, moveData)
emitSolitaireUpdate(gameState.userId, moveData);
tableau[i].pop()
foundations[foundationIndex].push(card)
//moveCard(gameState, moveData)
moves.push(moveData);
moved = true;
await sleep(500); // Pause for visualization
}
}
} while (moved)//(foundations.reduce((acc, pile) => acc + pile.length, 0));
return moves;
emitSolitaireUpdate(userId, moves)
}
/**

View File

@@ -142,15 +142,17 @@ export function solitaireRoutes(client, io) {
moveCard(gameState, moveData);
updateGameStats(gameState, 'move', moveData);
const canAutoSolve = checkAutoSolve(gameState);
if (canAutoSolve) {
gameState.autocompleting = true;
// TODO: start auto-completing moves with interval
await autoSolveMoves(gameState)
if (!gameState.autocompleting) {
const canAutoSolve = checkAutoSolve(gameState);
if (canAutoSolve) {
gameState.autocompleting = true;
autoSolveMoves(userId, gameState)
}
}
const win = checkWinCondition(gameState);
if (win) {
console.log("win")
gameState.isDone = true;
await handleWin(userId, gameState, io);
}

View File

@@ -346,4 +346,4 @@ export async function emitPokerToast(data) {
export const emitUpdate = (type, room) => io.emit("blackjack:update", { type, room });
export const emitToast = (payload) => io.emit("blackjack:toast", payload);
export const emitSolitaireUpdate = (userId, moveData) => io.emit('solitaire:update', {userId, moveData});
export const emitSolitaireUpdate = (userId, moves) => io.emit('solitaire:update', {userId, moves});