Skip to content

Tavern accepts a negative gambling bet, then contradicts itself with "You didn't bet any money!" #127

Description

@dmccoystephenson

Problem

Tavern.changeBet (src/location/tavern.py:242-256) only checks that the player can afford the amount:

self.amount = int(amount)

if self.player.canAfford(self.amount):
    self.currentBet = self.amount
    self.currentPrompt.text = (
        "What will the dice land on? Current Bet: $%d" % self.currentBet
    )

Player.canAfford is self.operatorMode or self.money >= cost (src/player/player.py:64-65), so any negative amount passes — money >= -100 is true for any balance. Entering -100 sets currentBet = -100 and the game reports "What will the dice land on? Current Bet: $-100".

Picking a number then hits the guard in Tavern.gamble (src/location/tavern.py:207):

if 1 <= input <= 6 and self.currentBet > 0:

which is false, so the player falls to the else branch and is told "You didn't bet any money!" — directly contradicting the bet the game just confirmed. There is no way to notice the bet was rejected other than trying to roll.

Not an exploit: because of the self.currentBet > 0 guard the losing branch (spendMoney(self.currentBet), which for a negative bet would add money) is unreachable. This is a validation and messaging bug, not a money bug.

Suggested fix

Reject amounts below $1 in changeBet with a message that says so, alongside the existing "not enough money" branch, so the confirmed bet always matches what gamble() will accept.

Test

tests/location/test_tavern.py already covers changeBet for the affordable and unaffordable cases; a negative-amount case belongs next to them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions