Add Bridzik.get_player_cards and make get_status player-agnostic
Engine support for the per-connection Socket.IO API: hands are fetched explicitly via get_player_cards(player) and the shared status no longer embeds a single player's cards.
This commit is contained in:
+9
-6
@@ -83,7 +83,7 @@ cards = [Card(color, value) for value in Card_values for color in Card_colors]
|
|||||||
|
|
||||||
|
|
||||||
class Bridzik():
|
class Bridzik():
|
||||||
def __init__(self, shuffler = shuffle):
|
def __init__(self, shuffler=shuffle):
|
||||||
self.shuffler = shuffler
|
self.shuffler = shuffler
|
||||||
self.series = [Series(0, 0, shuffler=self.shuffler)]
|
self.series = [Series(0, 0, shuffler=self.shuffler)]
|
||||||
|
|
||||||
@@ -99,13 +99,16 @@ class Bridzik():
|
|||||||
raise BridzikException('Hra je ukoncena.')
|
raise BridzikException('Hra je ukoncena.')
|
||||||
self.series[-1].add_player_guess(player, guess)
|
self.series[-1].add_player_guess(player, guess)
|
||||||
|
|
||||||
def get_status(self, player: int):
|
def get_player_cards(self, player: int):
|
||||||
|
player_cards = self.series[-1].get_last_round().player_cards[player]
|
||||||
|
return {k: v for k, v in enumerate(player_cards)}
|
||||||
|
|
||||||
|
def get_status(self):
|
||||||
status = {}
|
status = {}
|
||||||
last_series = self.series[-1]
|
last_series = self.series[-1]
|
||||||
if not self.is_completed():
|
if not self.is_completed():
|
||||||
status['active_player'] = last_series.get_last_round().get_active_player()
|
status['active_player'] = last_series.get_last_round().get_active_player()
|
||||||
status['active_round_guesses'] = last_series.get_last_round().guesses
|
status['active_round_guesses'] = last_series.get_last_round().guesses
|
||||||
status['player_cards'] = last_series.get_last_round().player_cards[player]
|
|
||||||
if last_series.get_last_round().is_guessing_completed():
|
if last_series.get_last_round().is_guessing_completed():
|
||||||
status['active_round_stashes'] = last_series.get_last_round().get_stashes_winner_summary()
|
status['active_round_stashes'] = last_series.get_last_round().get_stashes_winner_summary()
|
||||||
status['active_stash'] = {
|
status['active_stash'] = {
|
||||||
@@ -186,7 +189,7 @@ class Series():
|
|||||||
|
|
||||||
|
|
||||||
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):
|
||||||
# vyrob kopku pre toto kolo a priprav prazdne objekty
|
# vyrob kopku pre toto kolo a priprav prazdne objekty
|
||||||
if round_number not in [i for i in range(8)]:
|
if round_number not in [i for i in range(8)]:
|
||||||
raise BridzikException('Neplatne cislo kola.')
|
raise BridzikException('Neplatne cislo kola.')
|
||||||
@@ -285,7 +288,7 @@ class Round():
|
|||||||
def get_last_stash(self):
|
def get_last_stash(self):
|
||||||
return self.stashes[-1] if self.stashes else None
|
return self.stashes[-1] if self.stashes else None
|
||||||
|
|
||||||
def deal_starting_cards(self, cards: [], shuffler = shuffle):
|
def deal_starting_cards(self, cards: [], shuffler=shuffle):
|
||||||
self.round_cards = cards.copy()
|
self.round_cards = cards.copy()
|
||||||
shuffler(self.round_cards)
|
shuffler(self.round_cards)
|
||||||
self.round_cards = self.round_cards[(4*self.round_number):]
|
self.round_cards = self.round_cards[(4*self.round_number):]
|
||||||
@@ -308,7 +311,7 @@ class Round():
|
|||||||
self.stashes.append(Stash(self.get_last_stash().get_winner()))
|
self.stashes.append(Stash(self.get_last_stash().get_winner()))
|
||||||
|
|
||||||
|
|
||||||
class Stash():
|
class Stash:
|
||||||
def __init__(self, first_player: int):
|
def __init__(self, first_player: int):
|
||||||
if first_player not in [0, 1, 2, 3]:
|
if first_player not in [0, 1, 2, 3]:
|
||||||
raise BridzikException('Cislo hraca musi byt 0, 1, 2 alebo 3.')
|
raise BridzikException('Cislo hraca musi byt 0, 1, 2 alebo 3.')
|
||||||
|
|||||||
Reference in New Issue
Block a user