this.stacks = new Map();
this.hands = new Map();
this.bets = new Map();
+ this.ghosts = new Map();
this.pot = 0;
this.community = [];
this.user_icons = new Map();
chips_to_call() {
const max = Math.max(...this.bets.values());
+ const stack = this.stacks.get(this.username) || 0;
const bet = this.bets.get(this.username) || 0;
if (max >= 0) {
- return max - bet;
+ return Math.min(max - bet, stack);
} else {
return 0;
}
}
}
+ remove_ghosts() {
+ for (const [ghost, turns] of this.ghosts) {
+ if (turns === 0) {
+ this.seats.delete(ghost);
+ } else {
+ this.ghosts.set(ghost, turns - 1);
+ }
+ }
+ }
+
take_action(user_action) {
switch (user_action.action.action) {
case "Join":
this.redraw_players();
break;
case "KnockedOut":
- this.seats.delete(user_action.username);
this.stacks.delete(user_action.username);
if (this.hands.has(user_action.username)) {
for (const card of this.hands.get(user_action.username)) {
}
this.hands.delete(user_action.username);
this.bets.delete(user_action.username);
- if (this.active === user_action.username) {
- this.active = null;
+ const small_blind = this.player_after(this.dealer, () => true);
+ const big_blind = this.player_after(small_blind, () => true);
+ if (this.stacks.length <= 1) {
+ this.seats.delete(user_action.username);
+ } else if (user_action.username === this.dealer) {
+ this.ghosts.set(user_action.username, 0);
+ } else if (user_action.username === small_blind) {
+ this.ghosts.set(user_action.username, 1);
+ } else if (user_action.username === big_blind) {
+ this.ghosts.set(user_action.username, 2);
+ } else {
+ this.seats.delete(user_action.username);
}
this.redraw_cards();
this.redraw_players();
break;
case "NextToDeal":
+ this.remove_ghosts();
this.dealer = user_action.username;
for (const card of this.community) {
this.svg.removeChild(card.image);