Skip to content

Fix consecutive-wins bug in solution - #17

Open
XueyanZhang wants to merge 1 commit into
spiside:masterfrom
XueyanZhang:fix-solution-runner
Open

Fix consecutive-wins bug in solution#17
XueyanZhang wants to merge 1 commit into
spiside:masterfrom
XueyanZhang:fix-solution-runner

Conversation

@XueyanZhang

Copy link
Copy Markdown

Problem

runner.consecutive_wins += 1

consecutive_wins is never initialized.
The first time the player guesses correctly, the reference solution
crashes with:

AttributeError: 'GameRunner' object has no attribute 'consecutive_wins'

Fix

  • Track consecutive wins with a local consecutive_wins variable in
    run() (initialized to 0), removing the broken instance attribute.
  • Roll the dice each round so the game state actually changes between
    rounds. (I'm not sure if not re-rolling is intentional — happy to revert this if so.)

- remove uninitialized `runner.consecutive_wins` attribute
- roll the dice each round

@leespen1 leespen1 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request correctly changes the uninitialized runner.consecutive_wins to a function-local variable so that the program does not crash, and changes count to consecutive_wins so there is no redundancy (count is used to keep track of the number of consecutive wins).

This pull request also re-rolls the dice each round, so that the answer is not the same every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants