-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
57 lines (41 loc) · 1.62 KB
/
game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Game():
"""Game manages the sequence of actions that defines the game of Roulette.
This includes notifying the Player to place bets, spinning the Wheel and
resolving the Bets actually present on the Table."""
def __init__(self, wheel, table):
self.wheel = wheel
self.table = table
# PUBLIC
def cycle(self, player):
"""Execute a single cycle of play with a given Player.
It will call thePlayers placeBets() method to get bets. It will call
theWheels next() method to get the next winning Bin.
It will then call theTables iterator to get an Iterator over the Bets.
Stepping through this Iterator returns the individual Bet objects.
If the winning Bin contains the Outcome, call the thePlayer win()
method otherwise call the thePlayer lose() method.
Args:
player: A Player instance that places bets and get informed of
winning and loses of them.
Returns:
True if a cycle has been played.
False if player is done playing.
"""
# check if player is still playing
if not player.playing():
return False
# place bets
player.place_bets()
# spin the wheel
win_bin = self.wheel.next()
# anounce winners
player.winners(win_bin)
# iterate bets
table = player.get_table()
for bet in table:
# check if bet is a winning one
if bet.get_outcome() in win_bin:
player.win(bet)
else:
player.lose(bet)
return True