From 13eb629a16c248040a948e38d4fa72d6ba3e15dd Mon Sep 17 00:00:00 2001 From: BigGamerGary Date: Tue, 3 Feb 2026 18:35:49 +1000 Subject: [PATCH] Added machine spinning --- src/py/slots/Slots.py | 29 ++++++++++++++++-- src/py/slots/Wheel.py | 21 ++++++++++--- .../slots/__pycache__/Wheel.cpython-313.pyc | Bin 0 -> 1585 bytes 3 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 src/py/slots/__pycache__/Wheel.cpython-313.pyc diff --git a/src/py/slots/Slots.py b/src/py/slots/Slots.py index c4279e8..c71df0a 100644 --- a/src/py/slots/Slots.py +++ b/src/py/slots/Slots.py @@ -1,9 +1,34 @@ from Wheel import Wheel +from random import random class SlotMachine(): def __init__(self, screen_w=3, screen_h=3): jackpot = 0 - wheels=[] + self.wheels=[] for i in range(screen_w): wheel = Wheel(size=screen_h) - wheels.append(wheel) \ No newline at end of file + self.wheels.append(wheel) + + def spin(self, wSpins=3, randomness=0.5): + for _ in range(wSpins): + for wheel in self.wheels: + if random() >= randomness: + wheel.spin() + + + def __str__(self): + string = "" + for wheel in self.wheels: + string += str(wheel) + "\n" + return string + + +def main(): + # machine = SlotMachine() + # print(machine) + # machine.spin(randomness=1) + # print(machine) + pass + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/py/slots/Wheel.py b/src/py/slots/Wheel.py index d34fdf0..d2c9772 100644 --- a/src/py/slots/Wheel.py +++ b/src/py/slots/Wheel.py @@ -1,21 +1,32 @@ +""" +Wheel Class for implementing a wheel that spins in a poker machine +""" class Wheel(): def __init__(self, size=3): self.size=size self.icons = list(range(size)) - def roll(self, offset=1): + def spin(self, offset=1): new_icons = list(range(self.size)) + # Loop through each icon and move it one space up + # Uses modulus to loop final icon to first position for i, icon in enumerate(self.icons): new_icons[(i + offset) % len(new_icons)] = icon self.icons = new_icons + + def __str__(self): + string = "" + for icon in self.icons: + # Print wheel out with spaces between items + string += str(icon) + " " + return string def main(): - wheel = Wheel(size=10) - print(wheel.icons) - wheel.roll(offset=3) - print(wheel.icons) + # wheel = Wheel() + # print(wheel) + pass if __name__ == "__main__": diff --git a/src/py/slots/__pycache__/Wheel.cpython-313.pyc b/src/py/slots/__pycache__/Wheel.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..532b4f4f005a1649e88db524729d2ec6ca7faaff GIT binary patch literal 1585 zcmZ8h-D@0G6hC)9_N%+L&Br#o4`z(5Wi$zh4MLSdV~A2{kPNE}yEsfIvzyV`neDx^ zw40~+psZrSVuKY6MijK5Fa1x-g2bT@g+BEyaU;HZ&g{%qdtlBz_nvdlJ?D3ScSfaB z0Z@K_@Tpsq0iMt#6(uo7m(bV)131jV0vN0chO{D$y_^|x6}Z%t4dr4Tz{&wMr3F|? zHfzvU+p3<~Su1?F?KqzHj%Nv>wF0iWov!C}96xmZwq|KJVt2T0g_`KPzR+ABSG&O{ z4%a%Cz3uu=!A`QqLs9{ZmT|fVO~6{P5`%Hs$Qn`=K4x4oa#SB$s-a+=8AIjSc1F)f zYFy4!YSKU|nolo^#V`t_60F5E9MzdC=xo2aSHX z9r)U0z8Zwh%Qg@Ee&<>cYMahh?`BhQyV>nGg%{w~xY6ZqKgyY=>${<8MlX!l(m8b_ z&Y;?bgQ@aY`A4&rd*}9*?_V3vzA{j56-Ma#KT1??jM8st>_H>J0N@!$HP}oUMB5Wd zQA$T&YEZ6Na0jyIc}XLu;XN#|hZuD))K}}TFJWNgL>gU_(zvAzz6Q9edmT5-&(}nNQo^% zP9xz(3RQ@?(U|GWWYY;^9n~&8nwh&ddpG={|6PAr(T6jy4)Vttn0sk|=9lV^)j!TG ze(~<$^1+*LeSQ7*&d~_g}spJS?93 za{Wk!*?DaGRC!Q}n@$RdZ)-zmPw6}y2nsz%%=WF0gC`bDvlDFfJhF?XdA(_mrxZ$I%pM<2MnilNLv`a}N?8a^mS&(Zwbl>R7JNb(~l66GYElKq%CF zoSS;32-Bn=3nIN0*w{>58g1eWq~gTSa^~J1gK~*4qL+#hbl-