Exemplo n.º 1
0
    def test_everyone_agree_logic_regression(self):
        players = [Player("uuid%d" % i, 100) for i in range(4)]
        players[0].stack = 150
        players[1].stack = 150
        players[2].stack = 50
        players[3].stack = 50
        deck = Deck(cheat=True, cheat_card_ids=range(1, 53))
        table = Table(cheat_deck=deck)
        for player in players:
            table.seats.sitdown(player)
        table.dealer_btn = 3
        table.set_blind_pos(0, 1)

        state, _ = RoundManager.start_new_round(1, 5, 0, table)
        state, _ = RoundManager.apply_action(state, "raise", 15)
        state, _ = RoundManager.apply_action(state, "raise", 20)
        state, _ = RoundManager.apply_action(state, "raise", 25)
        state, _ = RoundManager.apply_action(state, "raise", 30)
        state, _ = RoundManager.apply_action(state, "raise", 50)
        state, _ = RoundManager.apply_action(state, "call", 50)
        state, _ = RoundManager.apply_action(state, "raise", 125)
        state, _ = RoundManager.apply_action(state, "call", 125)
        state, _ = RoundManager.apply_action(state, "fold", 0)
        state, _ = RoundManager.apply_action(state, "fold", 0)
        self.eq(Const.Street.FINISHED, state["street"])
    def test_update_game_when_game_finished(self):
        uuid_list = ["hoge", "fuga", "boo"]
        name_list = ["HOGE", "FUGA", "BOO"]
        players_info = Engine.gen_players_info(uuid_list, name_list)
        game_config = Engine.gen_game_config(5, 100, 10, 1)

        engine = Engine.EngineWrapper()
        engine.start_game(players_info, game_config)

        # Fix cards used in the game to make game result deterministic
        engine.current_state['table'].deck = Deck(cheat=True,
                                                  cheat_card_ids=range(6, 11))
        for idx, player in enumerate(
                engine.current_state['table'].seats.players):
            player.hole_card = [
                Card.from_id(idx * 2),
                Card.from_id(idx * 2 + 1)
            ]

        engine.update_game("raise", 99)
        engine.update_game("call", 99)
        original_msgs = engine.update_game("call", 99)
        hoge_msg, fuga_msg, boo_msg = [
            _simplify_messages(msgs)
            for msgs in _classify_messages_by_destination(
                original_msgs, uuid_list)
        ]
        self.eq([MSG_GU, MSG_SS, MSG_SS, MSG_SS, MSG_RF, MSG_GF], hoge_msg)
        self.eq([MSG_GU, MSG_SS, MSG_SS, MSG_SS, MSG_RF, MSG_GF], fuga_msg)
        self.eq([MSG_GU, MSG_SS, MSG_SS, MSG_SS, MSG_RF, MSG_GF], boo_msg)
Exemplo n.º 3
0
def determine_hand_strength_dist(community_card_list):
    prob_dict = {}
    deck = Deck()
    for card in community_card_list:
        deck.deck.remove(card)

    for possible_card_a in deck.deck:
        for possible_card_b in deck.deck:
            hand_strength = HandEvaluator.gen_hand_rank_info([possible_card_a, possible_card_b], community_card_list)['hand']['strength']
            if hand_strength == 'FLASH':
                hand_strength = 'FLUSH'
            if hand_strength == 'STRAIGHTFLASH':
                hand_strength = 'STRAIGHT FLUSH'

            if hand_strength in prob_dict:
                prob_dict[hand_strength] += 1
            else:
                prob_dict[hand_strength] = 1
    for key, value in prob_dict.items():
        prob_dict[key] = value / (len(deck.deck) ** 2)

    sorted_probs = sorted(prob_dict.items(), key=lambda kv: kv[1], reverse=True)

    value_list = [tuple[0] for tuple in sorted_probs]
    prob_list = [tuple[1] for tuple in sorted_probs]

    return value_list, prob_list
Exemplo n.º 4
0
 def test_cheat_serialization(self):
   cards = [Card.from_id(cid) for cid in [12, 15, 17]]
   cheat = Deck(cheat=True, cheat_card_ids=[12, 15, 17])
   serial = cheat.serialize()
   restored = Deck.deserialize(serial)
   self.eq(cheat.deck, restored.deck)
   self.eq(cheat.cheat, restored.cheat)
   self.eq(cheat.cheat_card_ids, restored.cheat_card_ids)
Exemplo n.º 5
0
def _restore_deck(str_exclude_cards):
    deck = Deck()
    exclude_ids = [Card.to_id(Card.from_str(s)) for s in str_exclude_cards]
    deck_cards = [
        Card.from_id(cid) for cid in range(1, 53) if cid not in exclude_ids
    ]
    deck.deck = deck_cards
    return deck
Exemplo n.º 6
0
 def __setup_table(self):
     players = [Player("uuid%d" % i, 100) for i in range(3)]
     deck = Deck(cheat=True, cheat_card_ids=range(1, 53))
     table = Table(cheat_deck=deck)
     for player in players: table.seats.sitdown(player)
     table.dealer_btn = 2
     table.set_blind_pos(0, 1)
     return table
Exemplo n.º 7
0
def gen_deck(exclude_cards=None):
    deck_ids = range(1, 53)
    if exclude_cards:
        assert isinstance(exclude_cards, list)
        if isinstance(exclude_cards[0], str):
            exclude_cards = [Card.from_str(s) for s in exclude_cards]
        exclude_ids = [card.to_id() for card in exclude_cards]
        deck_ids = [i for i in deck_ids if not i in exclude_ids]
    return Deck(deck_ids)
Exemplo n.º 8
0
def _restore_deck(str_exclude_cards):
    deck = Deck()
    exclude_ids = [Card.to_id(Card.from_str(s)) for s in str_exclude_cards]
    deck_cards = [
        Card.from_id(cid) for cid in Deck.GetFullDeck()
        if cid not in exclude_ids
    ]
    deck.cards = deck_cards
    return deck
Exemplo n.º 9
0
def gen_deck(exclude_cards=None):
    deck_ids = Deck.GetFullDeck()
    if exclude_cards:
        assert isinstance(exclude_cards, list)
        if isinstance(exclude_cards[0], str):
            exclude_cards = [Card.from_str(s) for s in exclude_cards]
        exclude_ids = [card for card in exclude_cards]
        deck_ids = [i for i in deck_ids if not i in exclude_ids]
    return Deck(deck_ids)
Exemplo n.º 10
0
def generate_holecard_ranking(nb_entry):
    nb_simulation = 1000
    deck = Deck()
    ranking = []
    for _ in range(nb_entry):
        deck.shuffle()
        hole = deck.draw_cards(2)
        win_rate = estimate_hole_card_win_rate(nb_simulation, 10, hole)
        ranking.append((win_rate, hole))
        deck.restore()
    return sorted(ranking)[::-1]
Exemplo n.º 11
0
    def __init__(self, num_players, num_rounds):
        self.round_count = 0
        self.community_from = 0
        self.cards = []
        for i in range(num_rounds):
            d = Deck()
            d.shuffle()
            cards = {'hole': [], 'community': d.draw_cards(5)}
            for j in range(num_players):
                cards['hole'].append(d.draw_cards(2))

            self.cards.append(cards)
Exemplo n.º 12
0
def subtask_hole_community_winrate(q, community_num, nb_sample):
    print "task started"
    nb_simulation = 1000
    deck = Deck()
    res = []
    for i in range(nb_sample):
        deck.shuffle()
        hole = deck.draw_cards(2)
        community = deck.draw_cards(community_num)
        win_rate = estimate_hole_card_win_rate(nb_simulation, 10, hole,
                                               community)
        res.append((win_rate, hole, community))
        deck.restore()
    q.put(res)
    print "task finished"
Exemplo n.º 13
0
def get_best_hand(community_card_list):
    hand_strength_set = {0}
    deck = Deck()
    for card in community_card_list:
        deck.deck.remove(card)
    for possible_card_a in deck.deck:
        deck.deck.remove(possible_card_a)
        for possible_card_b in deck.deck:
            hand_strength = HandEvaluator.eval_hand([possible_card_a, possible_card_b], community_card_list)
            if hand_strength > max(hand_strength_set):
                nuts_cards = {(str(possible_card_a), str(possible_card_b))}
            elif hand_strength == max(hand_strength_set):
                if not (str(possible_card_b), str(possible_card_a)) in nuts_cards:
                    nuts_cards.add((str(possible_card_a), str(possible_card_b)))
            hand_strength_set.add(hand_strength)
        deck.deck = [possible_card_a] + deck.deck
    return nuts_cards
 def __setup_deck(self, used_cards):
   deck = Deck()
   deck = self.__extract_used_card(deck, used_cards)
   deck.shuffle()
   return deck
Exemplo n.º 15
0
 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 = []
Exemplo n.º 16
0
 def test_cheat_restore(self):
   cards = [Card.from_id(cid) for cid in [12, 15, 17]]
   cheat = Deck(cheat=True, cheat_card_ids=[12, 15, 17])
   cheat.draw_cards(2)
   cheat.restore()
   self.eq(cheat.draw_cards(3), cards)
def gen_card_set(community_num):
  deck = Deck()
  deck.shuffle()
  return deck.draw_cards(2), deck.draw_cards(5)[:community_num]
Exemplo n.º 18
0
 def test_gen_deck_without_some_card(self):
     expected = Deck(deck_ids=range(2, 52))
     exclude_obj = [Card.from_id(1), Card.from_id(52)]
     exclude_str = [str(card) for card in exclude_obj]
     self.eq(expected.serialize(), U.gen_deck(exclude_obj).serialize())
     self.eq(expected.serialize(), U.gen_deck(exclude_str).serialize())
Exemplo n.º 19
0
 def setUp(self):
   self.deck = Deck()