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:
1 parent
8de55f7ca5
commit
b5d84e5f65
11 files changed
+408
-605
No files matched your search
@@ -1,96 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const crypto = require('crypto');
|
||||
|
||||
// カードは "As"(スペードのA), "Td"(ダイヤの10)のような2文字
|
||||
const RANKS = '23456789TJQKA';
|
||||
const SUITS = 'shdc';
|
||||
|
||||
// 暗号論的乱数で Fisher-Yates シャッフル(山札はサーバの外に出さない)
|
||||
function newDeck() {
|
||||
const deck = [];
|
||||
for (const r of RANKS) for (const s of SUITS) deck.push(r + s);
|
||||
for (let i = deck.length - 1; i > 0; i--) {
|
||||
const j = crypto.randomInt(i + 1);
|
||||
[deck[i], deck[j]] = [deck[j], deck[i]];
|
||||
}
|
||||
return deck;
|
||||
}
|
||||
|
||||
const rankValue = (card) => RANKS.indexOf(card[0]) + 2;
|
||||
|
||||
// 5枚の役の強さ。配列を先頭から比較して大きいほうが強い
|
||||
// [役の種類(0〜8), 比較用の数字...]
|
||||
function score5(cards) {
|
||||
const vals = cards.map(rankValue).sort((a, b) => b - a);
|
||||
const flush = cards.every((c) => c[1] === cards[0][1]);
|
||||
|
||||
let straightHigh = 0;
|
||||
if (new Set(vals).size === 5) {
|
||||
if (vals[0] - vals[4] === 4) straightHigh = vals[0];
|
||||
else if (vals[0] === 14 && vals[1] === 5) straightHigh = 5; // A-2-3-4-5
|
||||
}
|
||||
if (straightHigh && flush) return [8, straightHigh];
|
||||
|
||||
// 枚数の多い順、同じ枚数なら数字の大きい順
|
||||
const counts = new Map();
|
||||
for (const v of vals) counts.set(v, (counts.get(v) || 0) + 1);
|
||||
const groups = [...counts].sort((a, b) => b[1] - a[1] || b[0] - a[0]);
|
||||
const byGroup = groups.map((g) => g[0]);
|
||||
|
||||
if (groups[0][1] === 4) return [7, ...byGroup];
|
||||
if (groups[0][1] === 3 && groups[1][1] === 2) return [6, ...byGroup];
|
||||
if (flush) return [5, ...vals];
|
||||
if (straightHigh) return [4, straightHigh];
|
||||
if (groups[0][1] === 3) return [3, ...byGroup];
|
||||
if (groups[0][1] === 2 && groups[1][1] === 2) return [2, ...byGroup];
|
||||
if (groups[0][1] === 2) return [1, ...byGroup];
|
||||
return [0, ...vals];
|
||||
}
|
||||
|
||||
function compareScore(a, b) {
|
||||
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
||||
const d = (a[i] || 0) - (b[i] || 0);
|
||||
if (d) return d;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const HAND_NAMES = [
|
||||
'ハイカード',
|
||||
'ワンペア',
|
||||
'ツーペア',
|
||||
'スリーカード',
|
||||
'ストレート',
|
||||
'フラッシュ',
|
||||
'フルハウス',
|
||||
'フォーカード',
|
||||
'ストレートフラッシュ',
|
||||
];
|
||||
|
||||
function handName(score) {
|
||||
if (score[0] === 8 && score[1] === 14) return 'ロイヤルフラッシュ';
|
||||
return HAND_NAMES[score[0]];
|
||||
}
|
||||
|
||||
// 5〜7枚から最も強い5枚を選ぶ
|
||||
function bestHand(cards) {
|
||||
let best = null;
|
||||
const n = cards.length;
|
||||
const pick = (start, chosen) => {
|
||||
if (chosen.length === 5) {
|
||||
const score = score5(chosen);
|
||||
if (!best || compareScore(score, best.score) > 0) best = { score, cards: chosen.slice() };
|
||||
return;
|
||||
}
|
||||
for (let i = start; i <= n - (5 - chosen.length); i++) {
|
||||
chosen.push(cards[i]);
|
||||
pick(i + 1, chosen);
|
||||
chosen.pop();
|
||||
}
|
||||
};
|
||||
pick(0, []);
|
||||
return best && { score: best.score, cards: best.cards, name: handName(best.score) };
|
||||
}
|
||||
|
||||
module.exports = { newDeck, score5, compareScore, bestHand, handName };
|
||||
+1
-5
@@ -53,12 +53,8 @@ module.exports = {
|
||||
// 誰も接続していないテーブルを削除するまでの時間
|
||||
EMPTY_TABLE_TTL_MS: 30 * 60 * 1000,
|
||||
|
||||
// 1手の持ち時間。過ぎると自動でチェック/フォールドして離席扱い
|
||||
ACTION_TIME_MS: 30 * 1000,
|
||||
// オールインで残りのカードをめくる間隔
|
||||
RUNOUT_STEP_MS: 1500,
|
||||
// ハンド終了後、次のハンドまで結果を表示する時間
|
||||
SHOWDOWN_MS: 5000,
|
||||
SHOWDOWN_MS: 4000,
|
||||
FOLD_WIN_MS: 2500,
|
||||
// 参加者が2人揃ってから次のハンドを始めるまで
|
||||
NEXT_HAND_DELAY_MS: 2000,
|
||||
|
||||
+72
-122
@@ -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,
|
||||
};
|
||||
|
||||
@@ -228,6 +228,15 @@ io.on('connection', (socket) => {
|
||||
if (!Number.isSafeInteger(amount)) return '額が不正です';
|
||||
return t.act(token, p.type, amount);
|
||||
},
|
||||
'table:award': (t, token, p) => {
|
||||
// winners: ポットごとの勝者の席番号の配列
|
||||
const w = p && typeof p === 'object' ? p.winners : null;
|
||||
const ok =
|
||||
Array.isArray(w) &&
|
||||
w.length <= config.MAX_SEATS &&
|
||||
w.every((a) => Array.isArray(a) && a.length <= config.MAX_SEATS && a.every((s) => Number.isInteger(s)));
|
||||
return ok ? t.award(token, w) : '勝者の指定が不正です';
|
||||
},
|
||||
'table:sitOut': (t, token) => t.setSittingOut(token, true),
|
||||
'table:sitIn': (t, token) => t.setSittingOut(token, false),
|
||||
'table:rebuy': (t, token) => t.rebuy(token),
|
||||
|
||||
+33
-45
@@ -96,13 +96,13 @@ class Table {
|
||||
return free;
|
||||
}
|
||||
|
||||
leave(token, now = Date.now()) {
|
||||
leave(token) {
|
||||
const i = this.seatOf(token);
|
||||
if (i < 0 || this.seats[i].left) return false;
|
||||
if (this.hand && this.hand.players.has(i)) {
|
||||
// 結果表示やポット計算のため、ハンドが終わるまで席は残す
|
||||
this.seats[i].left = true;
|
||||
this.hand.forceFold(i, now);
|
||||
this.hand.forceFold(i);
|
||||
} else {
|
||||
this.seats[i] = null;
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class Table {
|
||||
return null;
|
||||
}
|
||||
|
||||
startNewHand(now) {
|
||||
startNewHand() {
|
||||
this.removeLeftSeats();
|
||||
const eligible = this.eligibleSeats();
|
||||
this.buttonSeat =
|
||||
@@ -139,26 +139,41 @@ class Table {
|
||||
this.handNumber++;
|
||||
const { sb, bb } = this.blinds;
|
||||
this.nextHandAt = null;
|
||||
this.hand = new Hand({ number: this.handNumber, seats: this.seats, order, button: this.buttonSeat, sb, bb, now });
|
||||
this.hand = new Hand({ number: this.handNumber, seats: this.seats, order, button: this.buttonSeat, sb, bb });
|
||||
}
|
||||
|
||||
// ---- プレイヤー操作(エラー時はメッセージを返す) ----
|
||||
|
||||
act(token, type, amount, now = Date.now()) {
|
||||
act(token, type, amount) {
|
||||
const i = this.seatOf(token);
|
||||
if (i < 0) return '着席していません';
|
||||
if (!this.handActive) return 'ハンドが進行していません';
|
||||
if (this.paused) return '一時停止中です';
|
||||
return this.hand.act(i, type, amount, now);
|
||||
return this.hand.act(i, type, amount);
|
||||
}
|
||||
|
||||
setSittingOut(token, value, now = Date.now()) {
|
||||
// ショーダウンの勝者を選べるのは、ショーダウンに残った人とホスト
|
||||
canAward(token) {
|
||||
if (!this.handActive || !this.hand.awaitingWinners) return false;
|
||||
const i = this.seatOf(token);
|
||||
const p = i >= 0 ? this.hand.players.get(i) : null;
|
||||
return this.isHost(token) || Boolean(p && !p.folded && !this.seats[i].left);
|
||||
}
|
||||
|
||||
award(token, winners) {
|
||||
if (!this.handActive || !this.hand.awaitingWinners) return 'ショーダウンではありません';
|
||||
if (!this.canAward(token)) return 'ショーダウンに残った人かホストが選んでください';
|
||||
if (this.paused) return '一時停止中です';
|
||||
return this.hand.award(winners);
|
||||
}
|
||||
|
||||
setSittingOut(token, value) {
|
||||
const i = this.seatOf(token);
|
||||
if (i < 0) return '着席していません';
|
||||
const s = this.seats[i];
|
||||
s.sittingOut = value;
|
||||
// 手番中に離席したら、その場でチェック/フォールド
|
||||
if (value && this.handActive && this.hand.toAct === i && !this.paused) this.hand.autoAct(now);
|
||||
if (value && this.handActive && this.hand.toAct === i && !this.paused) this.hand.autoAct();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -182,7 +197,7 @@ class Table {
|
||||
if (this.eligibleSeats().length < 2) return '2人以上必要です';
|
||||
this.started = true;
|
||||
if (this.timerEnabled) this.levelEndsAt = now + this.intervalMs;
|
||||
this.startNewHand(now);
|
||||
this.startNewHand();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -190,12 +205,8 @@ class Table {
|
||||
if (!this.isHost(token)) return 'ホストのみ操作できます';
|
||||
if (!this.started) return 'まだ開始していません';
|
||||
if (this.paused) {
|
||||
// 止めていた時間だけ各期限を後ろにずらす
|
||||
const shift = now - this.pausedAt;
|
||||
const h = this.hand;
|
||||
if (h && h.deadline != null) h.deadline += shift;
|
||||
if (h && h.runoutAt != null) h.runoutAt += shift;
|
||||
if (this.nextHandAt != null) this.nextHandAt += shift;
|
||||
// 止めていた時間だけ次のハンドの開始を後ろにずらす
|
||||
if (this.nextHandAt != null) this.nextHandAt += now - this.pausedAt;
|
||||
if (this.timerEnabled) this.levelEndsAt = now + this.levelRemainingMs;
|
||||
this.paused = false;
|
||||
this.pausedAt = null;
|
||||
@@ -210,7 +221,7 @@ class Table {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 時間で進む処理(ブラインドタイマー・手番の時間切れ・オールイン時のめくり・次のハンド)
|
||||
// 時間で進む処理(ブラインドタイマー・次のハンドの開始)
|
||||
// 状態が変わったら true
|
||||
tick(now) {
|
||||
let changed = false;
|
||||
@@ -221,24 +232,11 @@ class Table {
|
||||
}
|
||||
if (this.paused) return changed;
|
||||
|
||||
const h = this.hand;
|
||||
if (h && !h.finished) {
|
||||
if (h.toAct != null && now >= h.deadline) {
|
||||
this.seats[h.toAct].sittingOut = true; // 時間切れの人は離席扱い(戻るボタンで復帰)
|
||||
h.timeout(now);
|
||||
changed = true;
|
||||
}
|
||||
if (h.runoutAt != null && now >= h.runoutAt) {
|
||||
h.runoutStep(now);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.hand && this.hand.finished) {
|
||||
if (this.nextHandAt == null) {
|
||||
this.nextHandAt = now + (this.hand.showdown ? config.SHOWDOWN_MS : config.FOLD_WIN_MS);
|
||||
} else if (now >= this.nextHandAt) {
|
||||
if (this.canDeal()) this.startNewHand(now);
|
||||
if (this.canDeal()) this.startNewHand();
|
||||
else {
|
||||
this.hand = null;
|
||||
this.nextHandAt = null;
|
||||
@@ -250,7 +248,7 @@ class Table {
|
||||
if (!this.canDeal()) this.nextHandAt = null;
|
||||
else if (this.nextHandAt == null) this.nextHandAt = now + config.NEXT_HAND_DELAY_MS;
|
||||
else if (now >= this.nextHandAt) {
|
||||
this.startNewHand(now);
|
||||
this.startNewHand();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@@ -276,28 +274,17 @@ class Table {
|
||||
};
|
||||
}
|
||||
|
||||
// token = 閲覧者のトークン(他人のトークンや手札は送らない)
|
||||
// token = 閲覧者のトークン(他人のトークンは送らない)
|
||||
publicState(token, connectedTokens) {
|
||||
const now = Date.now();
|
||||
const { sb, bb } = this.blinds;
|
||||
const next = Blinds.blindsAt(this.baseSmallBlind, this.baseBigBlind, this.level + 1);
|
||||
const mySeat = this.seatOf(token);
|
||||
const h = this.hand;
|
||||
const hv = h ? h.view(mySeat, token) : null;
|
||||
const hv = h ? h.view() : null;
|
||||
const me = mySeat >= 0 ? this.seats[mySeat] : null;
|
||||
const inLiveHand = Boolean(this.handActive && h.players.has(mySeat) && !h.players.get(mySeat).folded);
|
||||
|
||||
let turn = null;
|
||||
if (this.handActive && h.toAct != null) {
|
||||
const remainingMs = Math.max(0, h.deadline - (this.paused ? this.pausedAt : now));
|
||||
turn = {
|
||||
seat: h.toAct,
|
||||
endsAt: this.paused ? null : h.deadline,
|
||||
remainingMs,
|
||||
totalMs: config.ACTION_TIME_MS,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
id: this.id,
|
||||
name: this.name,
|
||||
@@ -319,7 +306,7 @@ class Table {
|
||||
paused: this.paused,
|
||||
handNumber: this.handNumber,
|
||||
hand: hv,
|
||||
turn,
|
||||
toAct: this.handActive ? h.toAct : null,
|
||||
seats: this.seats.map((s, i) =>
|
||||
s && !s.left
|
||||
? {
|
||||
@@ -342,6 +329,7 @@ class Table {
|
||||
sittingOut: me.sittingOut,
|
||||
canRebuy: me.stack === 0 && !inLiveHand,
|
||||
options: this.handActive && !this.paused ? h.options(mySeat) : null,
|
||||
canAward: this.canAward(token),
|
||||
}
|
||||
: null,
|
||||
isHost: this.isHost(token),
|
||||
|
||||
Reference in new issue
Block a user