-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up fox-in-a-hole #198
Clean up fox-in-a-hole #198
Conversation
dstrain115
commented
Jul 4, 2024
- Add lots of comments and clean up some code paths
- Hopefully should make it easier to understand.
- Add lots of comments and clean up some code paths - Hopefully should make it easier to understand.
""" | ||
|
||
def __init__(self, hole_nr=5, seed=None): | ||
def __init__(self, number_of_holes: int = 5, seed: int = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seed: Optional[int] = None
since default value is not an int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
self.state = self.hole_nr * [0.0] | ||
index = self.rng.integers(low=0, high=self.hole_nr) | ||
# All holes start as empty | ||
self.state = self.number_of_holes * [0.0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe that's just me, but [0.0] * self.number_of_holes
reads better, intention of making a list of numbers of a certain size is clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -162,18 +247,25 @@ class QuantumGame(Game): | |||
(QuantumWorld, [QuantumObject]) -> quantum world, list of holes | |||
""" | |||
|
|||
def __init__(self, hole_nr=5, iswap=False, qprob=0.5, seed=None): | |||
def __init__(self, number_of_holes=5, iswap=False, qprob=0.5, seed=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type annotations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
for i, prob in enumerate(probs): | ||
if prob > 0: | ||
non_empty_holes.append(i) | ||
non_empty_holes = [i for i in range(len(probs)) if probs[i] > 0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list comprehension can be made nicer with [i for i, p in enumerate(probs) if p > 0]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.