Series init
This commit is contained in:
@@ -93,8 +93,58 @@ class Bridzik():
|
||||
pass
|
||||
|
||||
class Series():
|
||||
# self.rounds = []
|
||||
pass
|
||||
def __init__(self, series_number: int, first_player: int = None):
|
||||
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():
|
||||
def __init__(self, round_number: int, first_player: int, cards: []=cards, shuffler = shuffle):
|
||||
|
||||
Reference in New Issue
Block a user