Exemplo n.º 1
0
 def test_get_legal_actions(self):
     game = BidGame(players, num_players, starting_player,
                    num_cards_per_player, num_cards_dog, dog)
     game.init_game()
     actions = game.get_legal_actions()
     for action in actions:
         self.assertIn(action.get_str(), TarotBid.order.keys())
Exemplo n.º 2
0
 def test_get_payoffs_main(self):
     bid_game = BidGame(players, num_players, starting_player,
                        num_cards_per_player, num_cards_dog, dog)
     bid_game.init_game()
     game = MainGame(num_players, num_cards_per_player, starting_player,
                     players, taking_player_id, new_dog)
     game.init_game()
     while not game.is_over:
         actions = game.get_legal_actions()
         action = np.random.choice(actions)
         state, _ = game.step(action)
         print(len(state['hand']))
         print(len(state['others_hand']))
         print(len(state['played_cards']))
         total_cards = len(state['hand']) + len(state['others_hand']) + len(
             state['played_cards'])
         if game.taking_bid <= 3:
             self.assertEqual(total_cards, 72)  # Not counting the dog in it
         else:
             self.assertEqual(
                 total_cards,
                 78)  # Adding the dog in the others hand as not known cards
     payoffs = game.get_payoffs()
     total = 0
     for _, payoff in payoffs.items():
         total += payoff
     self.assertEqual(total, 0)
Exemplo n.º 3
0
    def init_game(self, number_of_deals: int = 0) -> (dict, int):
        """
        Initialize players and state for bid game in a globalgame object
        :return: (tuple): containing :

                (dict): the current state
                (int): next player id
        """
        self.current_game_part = 'BID'
        self.bid_over = False
        self.dog_over = False
        self.main_over = False
        self.number_of_deals = number_of_deals
        self.is_game_over = False
        self.players = [Player(i) for i in range(self.num_players)]
        self.dog = TarotDog()
        # Initialize bid Round
        self.bid_game = BidGame(self.players, self.num_players,
                                self.starting_player,
                                self.num_cards_per_player, self.num_cards_dog,
                                self.dog)

        self.bid_game.init_game()

        player_id = self.bid_game.bid_round.current_player_id
        state = self.bid_game.get_state(player_id)

        return state, player_id
Exemplo n.º 4
0
 def test_init_cards_main(self):
     bid_game = BidGame(players, num_players, starting_player,
                        num_cards_per_player, num_cards_dog, dog)
     bid_game.init_game()
     game = MainGame(num_players, num_cards_per_player, starting_player,
                     players, taking_player_id, new_dog)
     state, _ = game.init_game()
     self.assertEqual(len(list(state['hand'])), game.num_cards_per_player)
Exemplo n.º 5
0
 def test_step(self):
     game = BidGame(players, num_players, starting_player,
                    num_cards_per_player, num_cards_dog, dog)
     game.init_game()
     action = np.random.choice(game.get_legal_actions())
     current = game.bid_round.current_player_id
     state, next_player_id = game.step(action)
     self.assertLessEqual(len(state['other_bids']), num_players)
     self.assertEqual(next_player_id, (current + 1) % num_players)
Exemplo n.º 6
0
 def test_init_game(self):
     game = BidGame(players, num_players, starting_player,
                    num_cards_per_player, num_cards_dog, dog)
     state, _ = game.init_game()
     self.assertIsInstance(state['max_bid'], int)
     self.assertEqual(len(state['hand']), game.num_cards_per_player)
     actions = state['legal_actions']
     for action in actions:
         self.assertIn(action.get_str(), TarotBid.order.keys())
Exemplo n.º 7
0
 def test_step(self):
     bid_game = BidGame(players, num_players, starting_player,
                        num_cards_per_player, num_cards_dog, dog)
     bid_game.init_game()
     game = MainGame(num_players, num_cards_per_player, starting_player,
                     players, taking_player_id, new_dog)
     game.init_game()
     action = np.random.choice(game.get_legal_actions())
     state, next_player_id = game.step(action)
     current = game.main_round.current_player_id
     self.assertLessEqual(len(state['played_cards']), 2)
     self.assertEqual(next_player_id, current)
Exemplo n.º 8
0
 def test_init_game(self):
     bid_game = BidGame(players, num_players, starting_player,
                        num_cards_per_player, num_cards_dog, dog)
     bid_game.init_game()
     game = MainGame(num_players, num_cards_per_player, starting_player,
                     players, taking_player_id, new_dog)
     state, _ = game.init_game()
     total_cards = list(state['hand'] + state['others_hand'])
     self.assertIn(len(total_cards), [
         game.num_players * game.num_cards_per_player,
         game.num_players * game.num_cards_per_player + num_cards_dog
     ])
Exemplo n.º 9
0
 def test_step_back(self):
     bid_game = BidGame(players, num_players, starting_player,
                        num_cards_per_player, num_cards_dog, dog)
     bid_game.init_game()
     game = MainGame(num_players, num_cards_per_player, starting_player,
                     players, taking_player_id, new_dog)
     _, player_id = game.init_game()
     action = np.random.choice(game.get_legal_actions())
     self.assertEqual(game.main_round.current_player_id, player_id)
     game.step(action)
     self.assertEqual(game.main_round.current_player_id,
                      (player_id + 1) % game.num_players)
Exemplo n.º 10
0
 def test_get_final_bid(self):
     game = BidGame(players, num_players, starting_player,
                    num_cards_per_player, num_cards_dog, dog)
     game.init_game()
     while not game.bid_over:
         actions = game.get_legal_actions()
         action = np.random.choice(actions)
         state, _ = game.step(action)
         total_cards = len(state['hand'])
         self.assertEqual(total_cards, 18)
     taking_player_id = game.bid_round.taking_player_id
     self.assertIsInstance(taking_player_id, int)
     self.assertLessEqual(-game.bid_round.max_bid_order, -1)
Exemplo n.º 11
0
 def test_get_player_id(self):
     game = BidGame(players, num_players, starting_player,
                    num_cards_per_player, num_cards_dog, dog)
     _, player_id = game.init_game()
     current = game.get_player_id()
     self.assertEqual(player_id, current)
Exemplo n.º 12
0
 def test_get_action_num(self):
     game = BidGame(players, num_players, starting_player,
                    num_cards_per_player, num_cards_dog, dog)
     action_num = game.get_action_num()
     self.assertEqual(action_num, 6)
Exemplo n.º 13
0
 def test_get_player_num(self):
     game = BidGame(players, num_players, starting_player,
                    num_cards_per_player, num_cards_dog, dog)
     num_player = game.get_player_num()
     self.assertEqual(num_player, 4)
Exemplo n.º 14
0
from rlcard.games.tarot.bid.bid import TarotBid
from rlcard.games.tarot.utils import ACTION_LIST
from rlcard.games.tarot.utils import encode_hand, encode_target

num_players = 4
num_cards_per_player = 18
taking_player_id = random.randint(0, 3)
starting_player = random.randint(0, 3)
players = [Player(i) for i in range(num_players)]
num_cards_dog = 6
dog = TarotDog()

taking_bid = [TarotBid('POUSSE'), TarotBid('GARDE_CONTRE')][random.randint(0, 1)].get_bid_order()
taking_bid = TarotBid('POUSSE').get_bid_order()

bid_game = BidGame(players, num_players, starting_player, num_cards_per_player, num_cards_dog, dog)
bid_game.init_game()

players = bid_game.players
dog = bid_game.dog


class TestTarotBidGameMethods(unittest.TestCase):

    def test_get_action_num(self):
        game = DogGame(players, taking_player_id, num_cards_per_player, num_cards_dog, dog, taking_bid)
        action_num = game.get_action_num()
        self.assertEqual(action_num, 78)

    def test_init_game(self):
        game = DogGame(players, taking_player_id, num_cards_per_player, num_cards_dog, dog, taking_bid)