Fixed randomness - moved randomising to wheel class
This commit is contained in:
@@ -9,13 +9,13 @@ class SlotMachine():
|
|||||||
wheel = Wheel(size=screen_h)
|
wheel = Wheel(size=screen_h)
|
||||||
self.wheels.append(wheel)
|
self.wheels.append(wheel)
|
||||||
|
|
||||||
def spin(self, wSpins=3, randomness=0.5):
|
def spin(self, wSpins=3):
|
||||||
for _ in range(wSpins):
|
for _ in range(wSpins):
|
||||||
for wheel in self.wheels:
|
for wheel in self.wheels:
|
||||||
if random() >= randomness:
|
|
||||||
wheel.spin()
|
wheel.spin()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
string = ""
|
string = ""
|
||||||
# Create an empty matrix with the sole purpose of transposing it
|
# Create an empty matrix with the sole purpose of transposing it
|
||||||
@@ -39,8 +39,13 @@ class SlotMachine():
|
|||||||
def main():
|
def main():
|
||||||
machine = SlotMachine()
|
machine = SlotMachine()
|
||||||
print(machine)
|
print(machine)
|
||||||
machine.spin()
|
machine.spin(wSpins=1)
|
||||||
print(machine)
|
print(machine)
|
||||||
|
machine.spin(wSpins=1)
|
||||||
|
print(machine)
|
||||||
|
machine.spin(wSpins=1)
|
||||||
|
print(machine)
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
|
import random as rand
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Wheel Class for implementing a wheel that spins in a poker machine
|
Wheel Class for implementing a wheel that spins in a poker machine
|
||||||
"""
|
"""
|
||||||
class Wheel():
|
class Wheel():
|
||||||
def __init__(self, size=3):
|
def __init__(self, size=3, num_icons = 3):
|
||||||
self.size=size
|
self.size=size
|
||||||
self.icons = list(range(size))
|
self.icons = list(range(size))
|
||||||
|
self.num_icons = num_icons
|
||||||
|
|
||||||
def spin(self, offset=1):
|
def spin(self, offset=1):
|
||||||
new_icons = list(range(self.size))
|
new_icons = list(range(self.size))
|
||||||
@@ -13,6 +17,9 @@ class Wheel():
|
|||||||
for i, icon in enumerate(self.icons):
|
for i, icon in enumerate(self.icons):
|
||||||
new_icons[(i + offset) % len(new_icons)] = icon
|
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
|
self.icons = new_icons
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user