Fix consecutive-wins bug in solution - #17
Conversation
- remove uninitialized `runner.consecutive_wins` attribute - roll the dice each round
leespen1
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good catch, thanks for opening this PR @XueyanZhang !
Also, it is nice indeed to re-roll the dice on each iteration to make the gameplay more interesting - leveraging the already implemented roll(dice) function from the die module.
Finally, just one quick note: given that the counters for wins and loses (sic) are inside the runner object as attributes, wouldn't it be a good practice/idea to keep that pattern of the file and also let the consecutive_wins counter inside the runner object (as the previous buggy code was hinting)?
If you agree, I have also added the changes as suggestions below. This way, to avoid the previous bug we can just initialize self.consecutive_wins = 0 inside reset(self) (as it is done for the other counters for that run).
Thanks again for spotting this bug!
as per suggestion from @@rogerlucena Co-authored-by: Roger Leite Lucena <27161330+rogerlucena@users.noreply.github.com>
Co-authored-by: Roger Leite Lucena <27161330+rogerlucena@users.noreply.github.com>
Co-authored-by: Roger Leite Lucena <27161330+rogerlucena@users.noreply.github.com>
Co-authored-by: Roger Leite Lucena <27161330+rogerlucena@users.noreply.github.com>
Co-authored-by: Roger Leite Lucena <27161330+rogerlucena@users.noreply.github.com>
Co-authored-by: Roger Leite Lucena <27161330+rogerlucena@users.noreply.github.com>
|
@rogerlucena Great catch! I have revised per your suggestion. |
Problem
consecutive_winsis never initialized.The first time the player guesses correctly, the reference solution
crashes with:
AttributeError: 'GameRunner' object has no attribute 'consecutive_wins'Fix
run() (initialized to 0), removing the broken instance attribute.
rounds. (I'm not sure if not re-rolling is intentional — happy to revert this if so.)