Fixed randomness - moved randomising to wheel class
This commit is contained in:
@@ -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__":
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user