From e544b505f50c46d8cc99123ffd516171ea3480ae Mon Sep 17 00:00:00 2001 From: BigGamerGary Date: Tue, 3 Feb 2026 21:05:17 +1000 Subject: [PATCH] Fixed randomness - moved randomising to wheel class --- src/py/slots/Slots.py | 13 +++++++++---- src/py/slots/Wheel.py | 9 ++++++++- .../slots/__pycache__/Wheel.cpython-313.pyc | Bin 1585 -> 1712 bytes 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/py/slots/Slots.py b/src/py/slots/Slots.py index 9846765..c786e34 100644 --- a/src/py/slots/Slots.py +++ b/src/py/slots/Slots.py @@ -8,14 +8,14 @@ class SlotMachine(): for i in range(screen_w): wheel = Wheel(size=screen_h) self.wheels.append(wheel) - - def spin(self, wSpins=3, randomness=0.5): + + def spin(self, wSpins=3): for _ in range(wSpins): for wheel in self.wheels: - if random() >= randomness: wheel.spin() + def __str__(self): string = "" # Create an empty matrix with the sole purpose of transposing it @@ -39,8 +39,13 @@ class SlotMachine(): def main(): machine = SlotMachine() print(machine) - machine.spin() + machine.spin(wSpins=1) print(machine) + machine.spin(wSpins=1) + print(machine) + machine.spin(wSpins=1) + print(machine) + pass if __name__ == "__main__": diff --git a/src/py/slots/Wheel.py b/src/py/slots/Wheel.py index d2c9772..0190046 100644 --- a/src/py/slots/Wheel.py +++ b/src/py/slots/Wheel.py @@ -1,10 +1,14 @@ +import random as rand + + """ Wheel Class for implementing a wheel that spins in a poker machine """ class Wheel(): - def __init__(self, size=3): + def __init__(self, size=3, num_icons = 3): self.size=size self.icons = list(range(size)) + self.num_icons = num_icons def spin(self, offset=1): new_icons = list(range(self.size)) @@ -12,6 +16,9 @@ class Wheel(): # Uses modulus to loop final icon to first position for i, icon in enumerate(self.icons): new_icons[(i + offset) % len(new_icons)] = icon + + # Randomise the first element + new_icons[0] = rand.randint(0, self.num_icons - 1) self.icons = new_icons diff --git a/src/py/slots/__pycache__/Wheel.cpython-313.pyc b/src/py/slots/__pycache__/Wheel.cpython-313.pyc index 532b4f4f005a1649e88db524729d2ec6ca7faaff..303149578d415b119f548d7ad14df64f74bf934d 100644 GIT binary patch delta 901 zcmY*X&ubGw6n?WayUnIaY>~EUo7ObN)>SJWTEzMTwBkhwrAx75VF~FP7m|(4rk7G$ zJt!3{SQqiyp2S=Afp#ZMY2QHs5C=);$uIK~F=Y?xd&HJv zLxokCW9`zpxUoIc--bq+AB1T$@uTxzF&0O54 z*wV&L((JW(W&7dcnVK(44PUmSSMjPJDuInJs5ZhNZ0HUhQ>Nn~el|x6vHeFusFHUd z`hN8S*=h7f<+#Fcjk-%=1)wzv#iSH?E6IBb}Iz6hx=R>fVZu zu}c*4G)0*_8GjO2+E0)tM=%^G%z<&bsw+r(3L5C|MC5-4ErXlGtz^A&*4I_S^C-jf@U>Yq;(ASX6OR@^_v8qH z=02uPT&>j?7OVbsc@d-R8bU-?lQYJ?Ls!!>nD}G$uFp*5(WgcH0|f=KAOHXW delta 751 zcmYLGzfTlF6n^t-xt|a*InD!RyoRhIjS>=33eHeccrj9tY&OSmY~0%;Zx&3hK?;ox z#bx6kU}>U>+WBv2Zv4+lCBKpbC*u{!c^-0DA6)X%vSy`d%g`K@9QKjMG<5_N` zI~VO;7h#YYJ6j+AY~Ag`JF@BXoa<{-@SLGt=^b_qn_W7@9j z1(<0?(b4ll5ZH