Exemplo n.º 1
0
 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.")
Exemplo n.º 2
0
 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.")
Exemplo n.º 3
0
    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),
        }
Exemplo n.º 4
0
 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()
Exemplo n.º 5
0
 def test_info_rank(self):
     player = HanabiPlayer(player_id=0, cards=self.cards)
     player.inform_rank(Rank.ONE.value)
     player.render()
Exemplo n.º 6
0
 def test_info_color(self):
     player = HanabiPlayer(player_id=0, cards=self.cards)
     player.inform_color(Colors.BLACK)
     player.render()
Exemplo n.º 7
0
 def test_info_hidden(self):
     player = HanabiPlayer(player_id=0, cards=self.cards)
     player.render(can_see=False)
Exemplo n.º 8
0
 def test_init(self):
     player = HanabiPlayer(player_id=0, cards=self.cards)
     player.render()