mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-03-18 21:40:27 +01:00
feat: blackjack split
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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});
|
||||
Reference in New Issue
Block a user