def _restore_seats(seats_info, action_histories): players = [Player(info["uuid"], info["stack"], info["name"]) for info in seats_info] players_state = [info["state"] for info in seats_info] _restore_action_histories_on_players(players, action_histories) _restore_pay_info_on_players(players, players_state, action_histories) seats = Seats() seats.players = players return seats
def _restore_seats(seats_info, action_histories): players = [ Player(info['uuid'], info['stack'], info['name']) for info in seats_info ] players_state = [info['state'] for info in seats_info] _restore_action_histories_on_players(players, action_histories) _restore_pay_info_on_players(players, players_state, action_histories) seats = Seats() seats.players = players return seats
def test_serialization(self): table = self.__setup_players_with_table() for card in table.deck.draw_cards(3): table.add_community_card(card) table.shift_dealer_btn() table.set_blind_pos(1, 2) serial = table.serialize() restored = Table.deserialize(serial) self.eq(table.dealer_btn, restored.dealer_btn) self.eq(Seats.serialize(table.seats), Seats.serialize(restored.seats)) self.eq(Deck.serialize(table.deck), Deck.serialize(restored.deck)) self.eq(table.get_community_card(), restored.get_community_card()) self.eq(1, restored.sb_pos()) self.eq(2, restored.bb_pos())
def serialize(self): community_card = [card.to_id() for card in self._community_card] return [ self.dealer_btn, Seats.serialize(self.seats), Deck.serialize(self.deck), community_card, self._blind_pos ]
def test_serialization(self): self.__sitdown_players() serial = self.seats.serialize() restored = Seats.deserialize(serial) for i in range(len(self.seats.players)): self.eq(Player.serialize(self.seats.players[i]), Player.serialize(restored.players[i]))
def deserialize(self, serial): deck = Deck.deserialize(serial[2]) community_card = [Card.from_id(cid) for cid in serial[3]] table = self(cheat_deck=deck) table.dealer_btn = serial[0] table.seats = Seats.deserialize(serial[1]) table._community_card = community_card table._blind_pos = serial[4] return table
class SeatsTest(BaseUnitTest): def setUp(self): self.seats = Seats() self.p1 = Player("uuid1", 100) self.p2 = Player("uuid2", 100) self.p3 = Player("uuid3", 100) def test_sitdown(self): self.seats.sitdown(self.p1) self.true(self.p1 in self.seats.players) def test_size(self): self.__sitdown_players() self.eq(3, len(self.seats.players)) def test_count_active_players(self): self.__setup_pay_status() self.__sitdown_players() self.eq(2, self.seats.count_active_players()) def test_acount_ask_wait_players(self): self.__setup_pay_status() self.__sitdown_players() self.eq(1, self.seats.count_ask_wait_players()) def test_serialization(self): self.__sitdown_players() serial = self.seats.serialize() restored = Seats.deserialize(serial) for i in range(len(self.seats.players)): self.eq(Player.serialize(self.seats.players[i]), Player.serialize(restored.players[i])) def __setup_pay_status(self): self.p1.pay_info.update_by_pay(10) self.p2.pay_info.update_to_fold() self.p3.pay_info.update_to_allin() def __sitdown_players(self): for player in [self.p1, self.p2, self.p3]: self.seats.sitdown(player)
def __setup_seats(self): seats = Seats() for player in self.__setup_players(): seats.sitdown(player) return seats
def setup_seats(): seats = Seats() for _ in range(3): seats.sitdown(setup_player()) return seats
def __init__(self, cheat_deck=None): self.dealer_btn = 0 self._blind_pos = None self.seats = Seats() self.deck = cheat_deck if cheat_deck else Deck() self._community_card = []
def setUp(self): self.seats = Seats() self.p1 = Player("uuid1", 100) self.p2 = Player("uuid2", 100) self.p3 = Player("uuid3", 100)
def setUp(self): self.seats = Seats() self.p1 = Player('uuid1', 100) self.p2 = Player('uuid2', 100) self.p3 = Player('uuid3', 100)