Fix recursive gambling issue causing multiple "Go Back" selections - resolves #22#29
Conversation
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a recursive gambling issue where players had to select "Go Back" multiple times when exiting the gambling feature after changing their bet. The root cause was a recursive call to gamble() within the changeBet() method that created nested gambling loops.
- Removed recursive
self.gamble()call fromchangeBet()method - Fixed invalid error handling that called non-existent
self.deposit()method - Added test coverage to verify the fix prevents recursive gambling calls
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/location/tavern.py | Removed recursive gamble() call and fixed error handling in changeBet() method |
| tests/location/test_tavern.py | Added test to verify changeBet() no longer calls gamble() recursively |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| with MagicMock() as mock_input: | ||
| mock_input.return_value = '50' | ||
|
|
||
| # Temporarily replace the built-in input function | ||
| import builtins | ||
| original_input = builtins.input | ||
| builtins.input = mock_input |
There was a problem hiding this comment.
The with MagicMock() as mock_input: context manager is not actually managing the mocking of builtins.input. Consider using unittest.mock.patch instead for cleaner and more reliable input mocking.
| mock_input.return_value = '50' | ||
|
|
||
| # Temporarily replace the built-in input function | ||
| import builtins |
There was a problem hiding this comment.
The import statement should be placed at the top of the file with other imports rather than inside the test function.
Problem
Players were required to select "Go Back" multiple times when exiting the gambling feature after changing their bet. This occurred because the
changeBet()method in the tavern was callinggamble()recursively, creating nested gambling loops.Root Cause
In
src/location/tavern.py, the gambling flow worked as follows:changeBet()method processes the bet amountchangeBet()callsself.gamble()recursivelySolution
Primary Fix: Removed the recursive
self.gamble()call from thechangeBet()method. Instead of creating nested loops, the method now simply sets the bet amount and updates the prompt, then returns control to the main gambling loop.Before:
After:
Additional Fix: Corrected invalid error handling that was calling a non-existent
self.deposit()method, replacing it with proper prompt updates.Testing
test_changeBet_no_recursive_gambleto verify the fixImpact
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.