Switch to chips-only play: real cards at the table, winners picked on screen

- Remove the deck, hole cards, board, hand evaluator and reveal logic
  (cards are dealt physically; the site only tracks bets, pots and stacks)
- Showdown now waits for a winner per pot (main/side), chosen by a player
  still in the hand or the host; multiple winners split the pot
- All-in with no further betting goes straight to showdown
- Remove the 30s action clock / auto sit-out (everyone is at the same table)
- UI: winner picker panel (main winner auto-fills side pots), compact table

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
agomizi1cmandClaude Opus 5.5 committed 2026-10-15 17:46:10 +09:00
1 parent 8de55f7ca5
commit b5d84e5f65
11 files changed
+408 -605

No files matched your search

+72 -122
View File
@@ -1,13 +1,13 @@
'use strict';
const config = require('./config');
const { newDeck, bestHand, compareScore } = require('./cards');
// 1ハンド分の進行(配札・ベッティング・ショーダウン・ポット分配)
// 1ハンド分のチップの動き(ブラインド・ベッティング・ポット分配)。
// カードは実物で配るので扱わない。ショーダウンでは勝者をプレイヤーが選ぶ。
// seats は Table.seats への参照で、スタックはここで直接増減する。
// 参加者の席はハンド終了まで空席にならない(退席者は Table 側で予約したまま)。
const STREETS = ['PREFLOP', 'FLOP', 'TURN', 'RIVER'];
class Hand {
constructor({ number, seats, order, button, sb, bb, now }) {
constructor({ number, seats, order, button, sb, bb }) {
this.number = number;
this.seats = seats;
this.order = order; // 参加者の席番号。ボタンの次から時計回り
@@ -15,16 +15,11 @@ class Hand {
this.sb = sb;
this.bb = bb;
this.deck = newDeck();
this.board = [];
this.street = 'PREFLOP';
this.street = 'PREFLOP'; // PREFLOP / FLOP / TURN / RIVER / SHOWDOWN
this.pot = 0; // 前のストリートまでに集めた額
this.currentBet = 0;
this.minRaise = bb;
this.toAct = null;
this.deadline = null;
this.runoutAt = null;
this.revealed = false; // オールインで以降のアクションが無いとき、ショーダウン時に公開
this.finished = false;
this.showdown = false;
this.results = null;
@@ -34,7 +29,6 @@ class Hand {
this.players.set(i, {
seat: i,
token: seats[i].token,
cards: [],
bet: 0, // このストリートで出した額
committed: 0, // このハンドで出した合計
folded: false,
@@ -42,10 +36,8 @@ class Hand {
acted: false,
last: null, // 直前のアクション(表示用)
won: 0,
best: null,
});
}
for (let r = 0; r < 2; r++) for (const i of order) this.players.get(i).cards.push(this.deck.pop());
// ヘッズアップはボタンが SB
const headsUp = order.length === 2;
@@ -54,13 +46,17 @@ class Hand {
this.post(this.sbSeat, sb);
this.post(this.bbSeat, bb);
this.currentBet = bb; // BB がショートでもコール額は BB
this.setNextActor(this.bbSeat, now);
this.setNextActor(this.bbSeat);
}
get list() {
return this.order.map((i) => this.players.get(i));
}
get awaitingWinners() {
return this.street === 'SHOWDOWN' && !this.finished;
}
live() {
return this.list.filter((p) => !p.folded);
}
@@ -93,23 +89,21 @@ class Hand {
return actors.every((p) => !this.needsToAct(p));
}
setNextActor(fromSeat, now) {
setNextActor(fromSeat) {
this.toAct = null;
this.deadline = null;
if (this.bettingClosed()) return this.endStreet(now);
if (this.bettingClosed()) return this.endStreet();
const n = this.order.length;
const start = this.order.indexOf(fromSeat);
for (let k = 1; k <= n; k++) {
const p = this.players.get(this.order[(start + k) % n]);
if (!this.needsToAct(p)) continue;
this.toAct = p.seat;
this.deadline = now + config.ACTION_TIME_MS;
// 離席中・退席済みの人は自動でチェック/フォールド
const s = this.seats[p.seat];
if (s.sittingOut || s.left) this.autoAct(now);
if (s.sittingOut || s.left) this.autoAct();
return;
}
this.endStreet(now);
this.endStreet();
}
// 手番の人の選択肢(手番でなければ null)
@@ -132,7 +126,7 @@ class Hand {
}
// type: fold / check / call / raise(amount = このストリートでの合計額 "raise to")
act(seat, type, amount, now) {
act(seat, type, amount) {
const o = this.options(seat);
if (!o) return 'あなたの番ではありません';
const p = this.players.get(seat);
@@ -167,27 +161,27 @@ class Hand {
}
if (p.allIn) p.last = { type: 'ALLIN', amount: p.bet };
p.acted = true;
this.setNextActor(seat, now);
this.setNextActor(seat);
return null;
}
autoAct(now) {
autoAct() {
const o = this.options(this.toAct);
if (o) this.act(this.toAct, o.canCheck ? 'check' : 'fold', 0, now);
if (o) this.act(this.toAct, o.canCheck ? 'check' : 'fold', 0);
}
// 退席などで手番に関係なくフォールドさせる
forceFold(seat, now) {
forceFold(seat) {
const p = this.players.get(seat);
if (!p || p.folded || this.finished) return;
if (this.toAct === seat) return this.act(seat, 'fold', 0, now);
if (this.toAct === seat) return this.act(seat, 'fold', 0);
p.folded = true;
p.last = { type: 'FOLD' };
if (this.live().length === 1) {
this.runoutAt = null;
this.endStreet(now);
if (this.awaitingWinners) this.finishFoldWin();
else this.endStreet();
} else if (this.toAct != null && this.bettingClosed()) {
this.endStreet(now);
this.endStreet();
}
}
@@ -205,9 +199,8 @@ class Hand {
if (!p.allIn && p.last && p.last.type === 'ALLIN') p.last = null;
}
endStreet(now) {
endStreet() {
this.toAct = null;
this.deadline = null;
this.returnUncalled();
for (const p of this.list) {
this.pot += p.bet;
@@ -215,46 +208,17 @@ class Hand {
p.acted = false;
if (p.last && p.last.type !== 'FOLD' && p.last.type !== 'ALLIN') p.last = null;
}
if (this.live().length === 1) return this.finish(false);
if (this.street === 'RIVER') return this.finish(true);
if (this.live().length === 1) return this.finishFoldWin();
this.currentBet = 0;
this.minRaise = this.bb;
if (this.live().filter((p) => !p.allIn).length >= 2) {
this.dealStreet();
this.setNextActor(this.button, now);
} else {
// これ以上ベットが無いので手札を公開して残りのカードを順にめくる
this.revealed = true;
this.runoutAt = now + config.RUNOUT_STEP_MS;
// リバーが終わった、または全員オールインでこれ以上ベットが無い → ショーダウン
if (this.street === 'RIVER' || this.live().filter((p) => !p.allIn).length < 2) {
this.street = 'SHOWDOWN';
return;
}
}
dealStreet() {
this.deck.pop(); // バーン
if (this.street === 'PREFLOP') {
this.board.push(this.deck.pop(), this.deck.pop(), this.deck.pop());
this.street = 'FLOP';
} else if (this.street === 'TURN' || this.street === 'FLOP') {
this.board.push(this.deck.pop());
this.street = this.street === 'FLOP' ? 'TURN' : 'RIVER';
}
}
runoutStep(now) {
if (this.street === 'RIVER') {
this.runoutAt = null;
return this.finish(true);
}
this.dealStreet();
this.runoutAt = now + config.RUNOUT_STEP_MS;
}
// 手番の時間切れ。true なら時間切れ処理をした
timeout(now) {
if (this.finished || this.toAct == null || now < this.deadline) return false;
this.autoAct(now);
return true;
this.street = STREETS[STREETS.indexOf(this.street) + 1];
this.setNextActor(this.button);
}
// メインポット・サイドポット(同じ参加者のポットはまとめる)
@@ -276,72 +240,57 @@ class Hand {
return pots;
}
finish(showdown) {
finishFoldWin() {
const winner = this.live()[0];
winner.won = this.pot;
this.seats[winner.seat].stack += this.pot;
this.end(false, [{ amount: this.pot, winners: [winner.seat] }]);
}
// ショーダウンの勝者を決める。winners[i] = i 番目のポットの勝者の席番号(引き分けは複数)
award(winners) {
if (!this.awaitingWinners) return 'ショーダウンではありません';
const pots = this.buildPots();
if (!Array.isArray(winners) || winners.length !== pots.length) return 'すべてのポットの勝者を選んでください';
for (let i = 0; i < pots.length; i++) {
const w = winners[i];
if (!Array.isArray(w) || w.length === 0) return 'すべてのポットの勝者を選んでください';
if (new Set(w).size !== w.length || !w.every((s) => pots[i].eligible.includes(s))) return '勝者の指定が不正です';
}
const results = [];
pots.forEach((pot, i) => {
// 割り切れない端数はボタンの左から順に
const ws = this.order.filter((s) => winners[i].includes(s));
const share = Math.floor(pot.amount / ws.length);
let rest = pot.amount - share * ws.length;
for (const s of ws) {
const amount = share + (rest > 0 ? 1 : 0);
if (rest > 0) rest--;
this.players.get(s).won += amount;
this.seats[s].stack += amount;
}
results.push({ amount: pot.amount, winners: ws });
});
this.end(true, results);
return null;
}
end(showdown, results) {
this.finished = true;
this.showdown = showdown;
this.toAct = null;
this.deadline = null;
this.runoutAt = null;
const results = [];
if (!showdown) {
const winner = this.live()[0];
winner.won = this.pot;
this.seats[winner.seat].stack += this.pot;
results.push({ amount: this.pot, winners: [winner.seat], handName: null, bestCards: [] });
} else {
this.revealed = true;
for (const p of this.live()) p.best = bestHand(p.cards.concat(this.board));
for (const pot of this.buildPots()) {
const contenders = pot.eligible.map((s) => this.players.get(s));
let top = null;
for (const c of contenders) if (!top || compareScore(c.best.score, top) > 0) top = c.best.score;
const winners = contenders.filter((c) => compareScore(c.best.score, top) === 0);
// 割り切れない端数はボタンの左から順に
const share = Math.floor(pot.amount / winners.length);
let rest = pot.amount - share * winners.length;
for (const w of winners) {
const amount = share + (rest > 0 ? 1 : 0);
if (rest > 0) rest--;
w.won += amount;
this.seats[w.seat].stack += amount;
}
results.push({
amount: pot.amount,
winners: winners.map((w) => w.seat),
handName: winners[0].best.name,
bestCards: winners[0].best.cards,
});
}
}
this.pot = results.reduce((sum, r) => sum + r.amount, 0);
this.results = results;
}
// 閲覧者 viewerSeat に見せてよい情報だけを返す(他人の手札は公開時のみ)
view(viewerSeat, viewerToken) {
view() {
const players = {};
for (const p of this.list) {
const mine = p.seat === viewerSeat && p.token === viewerToken;
const shown = mine || (this.revealed && !p.folded);
let handName = null;
if (shown && !p.folded && this.board.length >= 3) {
handName = (p.best || bestHand(p.cards.concat(this.board))).name;
}
players[p.seat] = {
bet: p.bet,
folded: p.folded,
allIn: p.allIn,
last: p.last,
cards: shown ? p.cards : null,
handName,
won: p.won,
};
players[p.seat] = { bet: p.bet, folded: p.folded, allIn: p.allIn, last: p.last, won: p.won };
}
return {
number: this.number,
street: this.street,
board: this.board,
pot: this.pot,
potTotal: this.pot + this.list.reduce((sum, p) => sum + p.bet, 0),
currentBet: this.currentBet,
@@ -351,6 +300,7 @@ class Hand {
toAct: this.toAct,
finished: this.finished,
showdown: this.showdown,
pots: this.awaitingWinners ? this.buildPots() : null,
results: this.results,
players,
};