Series init

This commit is contained in:
Jakub Senderák
2020-03-28 21:20:37 +01:00
parent 3f3ba86ca3
commit c5207f3ad9
+52 -2
View File
@@ -93,8 +93,58 @@ class Bridzik():
pass pass
class Series(): class Series():
# self.rounds = [] def __init__(self, series_number: int, first_player: int = None):
pass self.series_number = series_number
self.first_player = first_player if first_player else series_number
self.rounds = []
self.start_new_round()
def add_player_guess(self, player: int, guess: int):
if self.get_last_round().is_completed():
raise BridzikException('Seria je ukoncena')
if player not in [0, 1, 2, 3]:
raise BridzikException('Cislo hraca musi byt 0, 1, 2 alebo 3.')
if self.get_last_round().is_guessing_completed():
raise BridzikException('Tipovanie ukoncene')
if player != self.get_last_round().get_active_player:
raise BridzikException('Hrac nie je na tahu')
self.get_last_round().add_player_guess(player, guess)
def play_card(self, player: int, card: Card):
if self.get_last_round().is_completed():
raise BridzikException('Seria je ukoncena')
if player not in [0, 1, 2, 3]:
raise BridzikException('Cislo hraca musi byt 0, 1, 2 alebo 3.')
if not self.get_last_round().is_guessing_completed():
raise BridzikException('Tipovanie nie je ukoncene.')
if player != self.get_last_round().get_active_player():
raise BridzikException('Hrac nie je na tahu')
self.get_last_round().play_card(player, card)
if self.get_last_round().is_completed() and not self.is_completed():
self.start_new_round()
def is_completed(self):
return len(self.rounds) == 8 and self.get_last_round().is_completed()
def get_standings(self):
standings = []
for round in self.rounds:
if round.is_completed():
standings.append(round.get_points_summary())
def get_last_round(self):
return self.rounds[-1] if self.rounds else None
def start_new_round(self):
if self.is_completed():
raise BridzikException('Seria je ukoncena.')
round_number = len(self.rounds)
if round_number != 0 and not self.get_last_round().is_completed():
raise BridzikException('Predchadzajuce kolo nie je ukoncene')
self.rounds.append(
Round(round_number, (self.first_player + round_number) % 4)
)
class Round(): class Round():
def __init__(self, round_number: int, first_player: int, cards: []=cards, shuffler = shuffle): def __init__(self, round_number: int, first_player: int, cards: []=cards, shuffler = shuffle):