From b2df6a5b499c1e2abcb48c510791044f1218ca51 Mon Sep 17 00:00:00 2001 From: milo Date: Mon, 20 Oct 2025 18:48:08 +0200 Subject: [PATCH] feat: blackjack split --- src/game/solitaire.js | 18 +++++++++--------- src/server/routes/solitaire.js | 12 +++++++----- src/server/socket.js | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/game/solitaire.js b/src/game/solitaire.js index e5adeef..a5f76eb 100644 --- a/src/game/solitaire.js +++ b/src/game/solitaire.js @@ -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) } /** diff --git a/src/server/routes/solitaire.js b/src/server/routes/solitaire.js index a69194e..9082d0e 100644 --- a/src/server/routes/solitaire.js +++ b/src/server/routes/solitaire.js @@ -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); } diff --git a/src/server/socket.js b/src/server/socket.js index 6343535..fc3a28b 100644 --- a/src/server/socket.js +++ b/src/server/socket.js @@ -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}); \ No newline at end of file +export const emitSolitaireUpdate = (userId, moves) => io.emit('solitaire:update', {userId, moves}); \ No newline at end of file