Example #1
0
 def test_encode_bid(self):
     bids = [TarotBid('PASSE'), TarotBid('PASSE'), TarotBid('GARDE_CONTRE')]
     plane = np.zeros((6, 5, 22), dtype=int)
     encode_bid(plane, bids, index_to_encode='2-0')
     total = 0
     for index1 in range(5):
         for index2 in range(22):
             total += plane[2][index1][index2]
     self.assertEqual(total, 3)
     self.assertEqual(plane[2][0][0], 2)
     self.assertEqual(plane[2][0][5], 1)
Example #2
0
    def proceed_round(self, players: List[TarotPlayer],
                      played_bid: TarotBid) -> int:
        """
        proceed bid round with a player bid
        :param players: List of TarotPlayer competing
        :param played_bid: the TarotBid object chosen by the current_player_id
        :return: the next player to speak
        """
        player = players[self.current_player_id]
        if player.bid is None:
            player.bid = played_bid
        if played_bid.get_str() != "PASSE":
            player.bid = played_bid
            self.taking_player_id = self.current_player_id
            player.taking = True
        if played_bid.get_str() == "PASSE":
            player.bid = played_bid
            player.taking = False

        self.max_bid_order = max(self.max_bid_order,
                                 played_bid.get_bid_order())
        self.max_bid = self.all_bids[self.max_bid_order]

        total_surrendered_players = 0
        for player_id in range(self.num_players):
            if players[player_id].bid is not None and players[
                    player_id].bid.get_str() == "PASSE":
                total_surrendered_players += 1

        # Maximal bid encountered
        # TODO REMOVE CONSTRAINTS THAT FORCE ONLY PASSE OU PETITE (2)
        if self.max_bid_order >= 1 or (total_surrendered_players
                                       == self.num_players - 1
                                       and self.taking_player_id is not None):
            for player_id in range(self.num_players):
                if player_id != self.taking_player_id:
                    players[player_id].taking = False
            self.is_over = True
        elif total_surrendered_players == self.num_players:
            self.is_dead = True
            return self.current_player_id

        # Define next speaking player within those that have not passed yet
        potential_next = (self.current_player_id + 1) % self.num_players
        if players[potential_next].bid is None:
            return potential_next
        else:
            while players[potential_next].bid.get_str() == 'PASSE':
                potential_next = (potential_next + 1) % self.num_players
            return potential_next
Example #3
0
def get_TarotBid_from_str(bid: str) -> Union[None, TarotBid]:
    """
    Get a TarotBid object from a string representation of a bid
    :param bid: str
    :return: TarotBid object
    """
    if bid is None:
        return None
    else:
        return TarotBid(bid)
Example #4
0
 def __init__(self, num_players: int, starting_player: int):
     """
     Initialize the bid round class
     :param num_players: (int) the number of players in game
     :param starting_player: (int) the starting player
     """
     self.current_player_id = starting_player
     self.num_players = num_players
     self.direction = 1
     self.max_bid_order = 0
     self.is_over = False
     self.is_dead = False
     self.taking_player_id = None
     self.all_bids = [
         TarotBid('PASSE'),
         TarotBid('PETITE'),
         TarotBid('POUSSE'),
         TarotBid('GARDE'),
         TarotBid('GARDE_SANS'),
         TarotBid('GARDE_CONTRE')
     ]
     self.max_bid = self.all_bids[self.max_bid_order]
Example #5
0
 def test_bid(self):
     bid1 = TarotBid('PASSE')
     bid2 = TarotBid('PETITE')
     self.assertLess(bid1.get_bid_order(), bid2.get_bid_order())
Example #6
0
    '19': 19,
    '20': 20,
    '21': 21
}

BID_SPACE = OrderedDict({
    'PASSE': 0,
    'PETITE': 1,
    'POUSSE': 2,
    'GARDE': 3,
    'GARDE_SANS': 4,
    'GARDE_CONTRE': 5
})
BID_LIST = list(BID_SPACE.keys())
all_bids = [
    TarotBid('PASSE'),
    TarotBid('PETITE'),
    TarotBid('POUSSE'),
    TarotBid('GARDE'),
    TarotBid('GARDE_SANS'),
    TarotBid('GARDE_CONTRE')
]


def init_deck() -> List[TarotCard]:
    """
    Generate tarot deck of 78 cards
    :return: List of TarotCards
    """
    card_deck = []
    card_info = Card.info
Example #7
0
from rlcard.games.tarot.bid.bid import TarotBid
from rlcard.games.tarot.bid.bid_game import BidGame
from rlcard.games.tarot.dog.dog import TarotDog
from rlcard.games.tarot.global_game import GlobalGame
from rlcard.games.tarot.main_game.main_game import MainGame
from rlcard.games.tarot.utils import ACTION_LIST, get_end_pot_information, get_nb_bouts
from rlcard.games.tarot.utils import hand2dict, encode_hand, encode_target, get_TarotCard_from_str

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)]
taking_bid = TarotBid('POUSSE')
players[taking_player_id].bid = taking_bid
players[taking_player_id].taking = True
new_dog = dog.hand


class TestTarotMainGameMethods(unittest.TestCase):
    def test_get_player_num(self):
        game = MainGame(num_players, num_cards_per_player, starting_player,
                        players, taking_player_id, new_dog)
        num_player = game.get_player_num()
        self.assertEqual(num_player, 4)

    def test_get_action_num(self):
Example #8
0
from rlcard.games.tarot.alpha_and_omega.player import TarotPlayer as Player
from rlcard.games.tarot.dog.dog import TarotDog
from rlcard.games.tarot.bid.bid_game import BidGame
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)