Skip to content

Commit

Permalink
Bugfix: Poker betting limits (#83)
Browse files Browse the repository at this point in the history
* Fix gameplay issues with poker

Fix an issue where the button order is not correct. Fix an issue where the timer
did not automatically end the round. Fix an issue where the game ending is still
sending an extra message.

* Change default poker timer to 300 seconds
  • Loading branch information
zeroclutch committed Sep 29, 2023
1 parent bc2c8a6 commit adb6f2a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions commands/dev/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import options from './../../config/options.js'
import { GAMEBOT_PERMISSIONS } from '../../config/types.js'

import BotCommand from '../../types/command/BotCommand.js'
import Game from '../../games/_Game/main.js'
export default new BotCommand({
name: 'debug',
aliases: ['db'],
Expand Down
35 changes: 26 additions & 9 deletions games/Poker/classes/Poker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import CardDeck from './CardDeck.js';

import logger from 'gamebot/logger'

// 🎉 🎉 🎉 Congrats to the `table.winners()` 🎉 🎉 🎉

class Poker extends Game {
constructor(msg, args) {
super(msg, args)
Expand All @@ -29,10 +27,10 @@ class Poker extends Game {
this.gameOptions = [
{
friendlyName: 'Timer',
default: '0',
default: 300,
type: 'number',
filter: m => !isNaN(m.content) && (isBetween(m.content, 20, 500) || m.content === '0'),
note: 'The time allowed for an action in seconds. Enter 0 to disable the timer.'
note: 'The time allowed for an action in seconds, between 20 and 500. Enter 0 to disable the timer.'
},
{
friendlyName: 'Small Blind',
Expand Down Expand Up @@ -73,15 +71,25 @@ class Poker extends Game {
]

this.BUTTON_STYLES = Object.freeze({
'fold': ButtonStyle.Danger,
'check': ButtonStyle.Secondary,
'view hand': ButtonStyle.Secondary,
'check': ButtonStyle.Primary,
'call': ButtonStyle.Primary,
'bet': ButtonStyle.Success,
'big bet': ButtonStyle.Success,
'raise': ButtonStyle.Success,
'view hand': ButtonStyle.Secondary,
'fold': ButtonStyle.Danger,
})

this.BUTTON_ORDER = Object.freeze([
'view hand',
'check',
'call',
'bet',
'big bet',
'raise',
'fold',
])

this.HAND_RANKINGS = Object.freeze([
'high card',
'pair',
Expand Down Expand Up @@ -134,7 +142,7 @@ class Poker extends Game {
}

getTimer() {
this.options['Timer'] === '0' ? null : parseInt(this.options['Timer']) * 1000
return this.options['Timer'] === '0' ? null : parseInt(this.options['Timer']) * 1000
}

getButtonStyle(action) {
Expand Down Expand Up @@ -283,6 +291,9 @@ class Poker extends Game {
.setStyle(this.getButtonStyle('view hand'))
)

// Sort actions
actionList.sort((a, b) => this.BUTTON_ORDER.indexOf(a.data.custom_id) - this.BUTTON_ORDER.indexOf(b.data.custom_id))

// Our custom actions must be registered for the collector filter
validActions.actions.push('big bet', 'view hand')

Expand Down Expand Up @@ -325,6 +336,7 @@ class Poker extends Game {
})

actionCollector.on('end', async (collected, reason) => {
if(this.ending) return
if (reason === 'time') {
// If the player didn't select an action in time, fold
this.inactiveRounds++
Expand Down Expand Up @@ -369,7 +381,8 @@ class Poker extends Game {
switch(this.options['Betting Limits']) {
case 'Pot Limit': {
minBet = validActions.chipRange.min
maxBet = this.table.pots().reduce((acc, pot) => acc + pot.size, 0)
// maxBet must always be at least the minimum bet
maxBet = Math.max(this.table.pots().reduce((acc, pot) => acc + pot.size, 0), minBet)
break
}
case 'Fixed Limit': {
Expand Down Expand Up @@ -480,6 +493,7 @@ class Poker extends Game {
})

betSizeCollector.on('end', async (collected, reason) => {
if(this.ending) return
if (reason === 'time') {
// If the player didn't select a bet size in time, fold
resolve(null)
Expand Down Expand Up @@ -519,6 +533,7 @@ class Poker extends Game {
})

betSizeCollector.on('end', async (collected, reason) => {
if(this.ending) return
if (reason === 'time') {
// If the player didn't select an action in time, fold
resolve(['fold', null])
Expand All @@ -541,6 +556,8 @@ class Poker extends Game {
table.startHand();

while (table.isHandInProgress()) {
if(this.ending) return

this.playersInHand = Array.from(this.players.keys());
while (table.isBettingRoundInProgress()) {
const seatIndex = table.playerToAct();
Expand Down

0 comments on commit adb6f2a

Please sign in to comment.