def test_discard(self): player = HanabiPlayer(player_id=0, cards=self.cards) card = player.discard(3) player.render() self.assertEqual(4, len(player._hand), f"Player didn't properly discard a card.") self.assertEqual(True, isinstance(card, HanabiCard), f"return value from discard isn't a card.")
def test_add_card(self): player = HanabiPlayer(player_id=0, cards=self.cards) player.add_card(HanabiCard(color=Colors.RED, rank=Rank.TWO)) player.render() self.assertEqual( 6, len(player._hand), f"Player didn't properly add a new card to his hand.")
def __init__(self, agents: list, hand_size=None, number_of_colors=5): assert 2 <= len(agents) <= 5, f"Requires 2-5 players, you entered {len(agents)}." self.agents = agents self.hand_size = hand_size if hand_size is not None else 5 if len(agents) <= 3 else 4 self.colors = [color for idx, color in enumerate(Colors.difficult()) if idx < number_of_colors] self.deck = HanabiDeck(colors=self.colors) self.players = [HanabiPlayer(idx, self.deck.provide_hand(self.hand_size)) for idx in range(len(agents))] self.obs_index, self.observation = self._create_observation_index() self.log = defaultdict(list) self.log_moves = dict() self.info = self._create_info() self.action_mapping = { 0: lambda action: self._action_play(action), 1: lambda action: self._action_inform_color(action), 2: lambda action: self._action_inform_rank(action), 3: lambda action: self._action_discard(action), }
def reset(self): self.deck.reset() self.players = [HanabiPlayer(idx, self.deck.provide_hand(self.hand_size)) for idx in range(len(self.agents))] self.log = defaultdict(list) self.info = self._create_info() return self._get_observation()
def test_info_rank(self): player = HanabiPlayer(player_id=0, cards=self.cards) player.inform_rank(Rank.ONE.value) player.render()
def test_info_color(self): player = HanabiPlayer(player_id=0, cards=self.cards) player.inform_color(Colors.BLACK) player.render()
def test_info_hidden(self): player = HanabiPlayer(player_id=0, cards=self.cards) player.render(can_see=False)
def test_init(self): player = HanabiPlayer(player_id=0, cards=self.cards) player.render()