58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
import { handValue, canDouble, canSplit } from './BlackjackLogic.js';
|
|
|
|
// ─── Bet sizing ───────────────────────────────────────────────────────────────
|
|
|
|
export function chooseBet(player) {
|
|
const options = [5, 10, 15, 25];
|
|
const raw = options[Math.floor(Math.random() * options.length)];
|
|
return Math.min(raw, player.chips, 100);
|
|
}
|
|
|
|
// ─── Action selection (basic strategy) ───────────────────────────────────────
|
|
|
|
export function chooseAction(player, dealerUpcard) {
|
|
const hand = player.activeHand === 1 ? player.hand2 : player.hand;
|
|
const { score, soft } = handValue(hand);
|
|
const upVal = Math.min(dealerUpcard.value, 10); // treat 10/J/Q/K as 10
|
|
|
|
// Split decisions
|
|
if (canSplit(player)) {
|
|
const rank = player.hand[0].rank;
|
|
if (rank === 'A' || rank === '8') return 'split';
|
|
if (rank === '5' || rank === 'T' || rank === 'J' || rank === 'Q' || rank === 'K') {
|
|
// never split 5s or 10-values
|
|
} else if (upVal >= 2 && upVal <= 6) {
|
|
return 'split';
|
|
}
|
|
}
|
|
|
|
// Double decisions
|
|
if (canDouble(player)) {
|
|
if (!soft) {
|
|
if (score === 11) return 'double';
|
|
if (score === 10 && upVal <= 9) return 'double';
|
|
if (score === 9 && upVal >= 3 && upVal <= 6) return 'double';
|
|
} else {
|
|
// Soft doubles
|
|
if ((score === 17 || score === 18) && upVal >= 3 && upVal <= 6) return 'double';
|
|
}
|
|
}
|
|
|
|
// Soft totals
|
|
if (soft) {
|
|
if (score >= 19) return 'stand';
|
|
if (score === 18) return upVal >= 9 ? 'hit' : 'stand';
|
|
return 'hit';
|
|
}
|
|
|
|
// Hard totals
|
|
if (score >= 17) return 'stand';
|
|
if (score >= 13 && upVal <= 6) return 'stand';
|
|
if (score === 12 && upVal >= 4 && upVal <= 6) return 'stand';
|
|
return 'hit';
|
|
}
|
|
|
|
export function chooseInsurance() {
|
|
return false; // AI always declines insurance
|
|
}
|