From 59bbca5c00a092e6b0fa92a07053d0812aae84d4 Mon Sep 17 00:00:00 2001 From: milo Date: Mon, 20 Oct 2025 18:47:47 +0200 Subject: [PATCH] feat: solitaire autocomplete --- src/game/blackjack.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/game/blackjack.js b/src/game/blackjack.js index 26ab51d..7e38c8a 100644 --- a/src/game/blackjack.js +++ b/src/game/blackjack.js @@ -7,7 +7,8 @@ import {getUser, insertLog, updateUserCoins} from "../database/index.js"; import {client} from "../bot/client.js"; import {EmbedBuilder} from "discord.js"; -export const RANKS = ["A","2","3","4","5","6","7","8","9","T","J","Q","K"]; +// export const RANKS = ["A","2","3","4","5","6","7","8","9","T","J","Q","K"]; +export const RANKS = ["A", "2"]; export const SUITS = ["d","s","c","h"]; // Build a single 52-card deck like "Ad","Ts", etc. @@ -201,7 +202,7 @@ export function dealInitial(room) { const actives = Object.values(room.players).filter(p => p.currentBet >= room.minBet); for (const p of actives) { p.inRound = true; - p.hands = [ { cards: [draw(room.shoe)], stood: false, busted: false, doubled: false, surrendered: false, hasActed: false, bet: 0 } ]; + p.hands = [ { cards: [draw(room.shoe)], stood: false, busted: false, doubled: false, surrendered: false, hasActed: false, bet: p.currentBet } ]; } room.dealer.cards = [draw(room.shoe), draw(room.shoe)]; room.dealer.holeHidden = true; @@ -252,7 +253,12 @@ export async function settleAll(room) { surrendered: hand.surrendered, blackjackPayout: room.settings.blackjackPayout, }); - allRes[p.id] = res; + if (allRes[p.id]) { + allRes[p.id].push(res); + } else { + allRes[p.id] = [res]; + } + p.totalDelta += res.delta p.totalBets++ if (res.result === 'win' || res.result === 'push' || res.result === 'blackjack') { @@ -323,27 +329,22 @@ export function applyAction(room, playerId, action) { case "stand": { hand.stood = true; hand.hasActed = true; + p.activeHand++; return "stand"; } case "double": { if (!canDouble(hand)) throw new Error("Cannot double now"); hand.doubled = true; hand.bet*=2 - p.currentBet*=2 + p.currentBet+=hand.bet/2 hand.hasActed = true; // The caller (routes) must also handle additional balance lock on the bet if using real coins hand.cards.push(draw(room.shoe)); if (isBust(hand.cards)) hand.busted = true; else hand.stood = true; + p.activeHand++; return "double"; } - case "surrender": { - if (hand.cards.length !== 2 || hand.hasActed) throw new Error("Cannot surrender now"); - hand.surrendered = true; - hand.stood = true; - hand.hasActed = true; - return "surrender"; - } case "split": { if (hand.cards.length !== 2) throw new Error("Cannot split: not exactly 2 cards"); const r0 = hand.cards[0][0];