示例#1
0
 def test_contains(self):
     h2 = Card('h2')
     h3 = Card('h3')
     h4 = Card('h4')
     h5 = Card('h5')
     group1 = CardSet([h2, h3])
     group2 = CardSet([h4, h5])
     table = Table([group1, group2])
     self.assertTrue(table.contains(group2))
     self.assertFalse(table.contains(h2))
示例#2
0
 def test_append(self):
     table = Table()
     h2 = Card('h2')
     h3 = Card('h3')
     h4 = Card('h4')
     h5 = Card('h5')
     group = CardSet([h2, h3, h4])
     table.add_cards(group)
     table.add_cards(CardSet(h5))
     comparison_table = Table([CardSet([h2, h3, h4]), CardSet(h5)])
     self.assertTrue(table == comparison_table)
示例#3
0
 def test_contains(self):
     h3 = Card('h3')
     h4 = Card('h4')
     h5 = Card('h5')
     h6 = Card('h6')
     child_group = CardSet([h3, h4, h5])
     parent_group = CardSet([h3, h4, h5, h6])
     self.assertTrue(parent_group.contains(child_group))
     self.assertTrue(child_group.isin(parent_group))
     self.assertFalse(child_group.contains(parent_group))
     self.assertTrue(child_group.contains(h3))
     self.assertTrue(child_group.contains(CardSet(h3)))
示例#4
0
    def test_append_extend(self):
        # case 1: appending a card object:
        h3 = Card('h3')
        group = CardSet(h3)
        h4 = Card('h4')
        group.append(h4)
        self.assertTrue(group == CardSet([h3, h4]))

        # case 2: appending a card_set object
        card_set = CardSet([h3, h4])
        group.extend(card_set)
        self.assertTrue(group == CardSet([h3, h3, h4, h4]))
示例#5
0
 def test_add_to_target(self):
     h2 = Card('h2')
     h3 = Card('h3')
     h4 = Card('h4')
     h5 = Card('h5')
     h6 = Card('h6')
     h7 = Card('h7')
     group1 = CardSet([h2, h3])
     group2 = CardSet([h4, h5])
     group3 = CardSet([h6, h7])
     table = Table([group1, group2])
     table.add_cards_to_target_cards(added_set=group3, target_set=group2)
     self.assertTrue(table == Table([group1, CardSet([h4, h5, h6, h7])]))
示例#6
0
    def test_remove(self):
        # case 1: removing a card object
        h3 = Card('h3')
        h4 = Card('h4')
        h5 = Card('h5')
        group = CardSet([h3, h4, h5])
        card2remove = h3
        group.remove(card2remove)
        self.assertTrue(group == CardSet([h4, h5]))
        self.assertFalse(group.contains(h3))
        self.assertFalse(h3.isin(group))

        # case 2: removing a card_set object
        group = CardSet([h3, h4, h5])
        to_remove = CardSet([h3, h4])
        group.remove(to_remove)
        self.assertTrue(group == CardSet(h5))
示例#7
0
def input_to_card_set(input: str):
    '''Transforms user input string into a cardset object'''
    if input == 'finished':
        return('finished')
    card_strings = input.strip().split(', ')
    card_lst = [Card(cs) for cs in card_strings]
    card_set = CardSet(card_lst)
    return(card_set)
示例#8
0
 def test_sort(self):
     s2 = Card('s2')
     s2.hidden_suit = 'h'
     s2.hidden_int_value = 5
     s2.hidden_rank = '5'
     h4 = Card('h4')
     h6 = Card('h6')
     d2 = Card('d2')
     d2 = Card('d2')
     d2.hidden_suit = 'd'
     d2.hidden_int_value = 7
     d2.hidden_rank = '7'
     group = CardSet([h4, s2, d2, h6])
     group.sort_cards()
     comparison_group = CardSet([h4, s2, h6,
                                 d2])  # what the cards should look like
     self.assertEqual(group.card_ids, comparison_group.card_ids)
示例#9
0
    def test_eq(self):
        h3 = Card('h3')
        group = CardSet(h3)
        self.assertFalse(h3 == group)

        h2 = Card('h2')
        h4 = Card('h4')
        h5 = Card('h5')
        h6 = Card('h6')

        h2.assign_wildcard_attrs()  # assign 'h' and 4 as hidden attrs
        group1 = CardSet([h2, h5, h6])
        group2 = CardSet([h4, h5, h6])
        self.assertTrue(h2 == h4)
        self.assertTrue(group1 == group2)
        self.assertTrue(group1.contains(group2))

        group2.remove(
            h2
        )  # since h2 and h4 are equal, removing h2 should in effect remove h4
        self.assertTrue(group2 == CardSet([h5, h6]))

        group2 = CardSet([h4, h5, h6])
        group2.remove(CardSet([h2, h5]))
        print(group2)
        self.assertTrue(group2 == CardSet([h6]))
示例#10
0
 def test_most_common_rank(self):
     sample_set = CardSet()
     sample_set.add_card(Card('5s'))
     sample_set.add_card(Card('5c'))
     sample_set.add_card(Card('6h'))
     sample_set.add_card(Card('Jh'))
     result = sample_set.most_common_rank()
     print(sample_set.to_string())
     self.assertEqual(result, Card.FIVE)
示例#11
0
 def test_most_common_suit(self):
     sample_set = CardSet()
     sample_set.add_card(Card('5s'))
     sample_set.add_card(Card('6s'))
     sample_set.add_card(Card('7h'))
     sample_set.add_card(Card('Jc'))
     result = sample_set.most_common_suit()
     print(sample_set.to_string())
     self.assertEqual(result, Card.SPADES)
示例#12
0
def main() -> None:
    with open('cah-cards-full.json', 'r') as f:
        sets = [CardSet(**_set) for _set in json.load(f)]

    deck = Deck(*sets)
    game = Game(
        deck=deck,
        players=[Player('Tom'),
                 Player('Beatrice'),
                 Player('Beatrice 2')])

    game.play()
示例#13
0
def make_files():
    all_sets_json = AllSetsReader.read(ALL_SETS_JSON_PATH)

    for card_set_dict in AllSetsReader.split_sets(all_sets_json):
        card_set = CardSet(card_set_dict)

        path = "{sets_directory}/{set_name}.json".format(
            sets_directory=SETS_DIRECTORY, set_name=''.join([char for char in card_set.name if char.isalnum()])
        )

        card_set.to_file(path)

        yield path
示例#14
0
    def test_consecutive(self):
        s2 = Card('s2')
        s2.hidden_int_value = 5
        s2.hidden_suit = 'h'
        s2.hidden_rank = '5'
        h4 = Card('h4')
        h6 = Card('h6')

        # case 1
        group = CardSet([h4, s2, h6])
        self.assertTrue(group.consecutive)
        self.assertFalse(group.same_rank)
        self.assertTrue(group.wc_is_in_cards)

        # case 2
        d2 = Card('d2')
        d2.hidden_suit = 'd'
        d2.hidden_int_value = 7
        d2.hidden_rank = '7'
        group = CardSet([h4, s2, h6, d2])
        self.assertTrue(group.consecutive)
        self.assertFalse(group.same_rank)

        # case 3
        group = CardSet([s2, h4, h6])
        self.assertFalse(group.consecutive)
        self.assertFalse(group.same_rank)
        self.assertTrue(group.wc_is_in_cards)

        # case 4
        d5 = Card('d5')
        c5 = Card('c5')
        group = CardSet([s2, d5, c5])
        self.assertFalse(group.consecutive)
        self.assertTrue(group.same_rank)
        self.assertTrue(group.wc_is_in_cards)
示例#15
0
def write_table():
    table = {}
    t = time.time()
    for c1, c2, c3, c4, c5 in combinations(
            product(STR_RANKS.keys(), STR_SUITS), 5):
        cset = CardSet([
            Card("".join(c1)),
            Card("".join(c2)),
            Card("".join(c3)),
            Card("".join(c4)),
            Card("".join(c5))
        ])
        flop_eval = FlopEvaluator(cset)
        made = flop_eval.get_made()
        table[cset.get_bin()] = made.keys()[made.values().index(True)]
    with open('./lut/test.lut', 'w') as f:
        json.dump(table, f)
    print t, time.time(), time.time() - t
示例#16
0
    def test_isin(self):
        # case 1
        h3 = Card('h3')
        h4 = Card('h4')
        h5 = Card('h5')
        group = CardSet([h3, h4, h5])
        self.assertTrue(h3.isin(group))

        # case 2: wildcard
        c2 = Card('c2')
        c2.hidden_suit = 'H'
        c2.hidden_int_value = 3
        c2.hidden_rank = '3'
        self.assertTrue(c2.isin(group))
        self.assertTrue(
            c2 == h3
        )  # c2 is considered to be in the group since c2 == h3 after assigning new attrs
        c2.reset_wildcard_attrs()
        self.assertFalse(
            c2.isin(group)
        )  # c2 is no longer in the group after resetting its attributes
        self.assertFalse(c2 == h3)
示例#17
0
def input_to_card_set(input):
    card_strings = input.strip().split(', ')
    card_lst = [Card(cs) for cs in card_strings]
    card_set = CardSet(card_lst)
    return (card_set)
示例#18
0
def _combo_to_hand(combo):
    return CardSet([Card(combo[:2]), Card(combo[2:])])
示例#19
0
        cset = CardSet([
            Card("".join(c1)),
            Card("".join(c2)),
            Card("".join(c3)),
            Card("".join(c4)),
            Card("".join(c5))
        ])
        flop_eval = FlopEvaluator(cset)
        made = flop_eval.get_made()
        table[cset.get_bin()] = made.keys()[made.values().index(True)]
    with open('./lut/test.lut', 'w') as f:
        json.dump(table, f)
    print t, time.time(), time.time() - t


def read_table():
    with open('./lut/test.lut', 'r') as f:
        return json.load(f)


if __name__ == '__main__':
    c1 = Card('7c')
    c2 = Card('5c')
    c3 = Card('4c')
    c4 = Card('3c')
    c5 = Card('2s')

    cset = CardSet([c4, c2, c3, c1, c5])
    table = read_table()
    print table[u'%d' % cset.get_bin()]
示例#20
0
 def __init__(self, card_set=None):
     if card_set is None:
         self.card_set = CardSet()
     else:
         self.card_set = card_set
示例#21
0
import time
from itertools import product, combinations

import basic_lut
from card import Card
from cardset import CardSet
from evaluator import FlopEvaluator
from tools import STR_RANKS, STR_SUITS

c1 = Card('Ah')
c2 = Card('Kh')
c3 = Card('Qh')
c4 = Card('Jh')
c5 = Card('Th')

cset = CardSet([c4, c2, c3, c1, c5])
print "{0:b}".format(cset.get_bin())
flop_eval = FlopEvaluator(cset)

print cset

print flop_eval.get_made()

m = {
    "Straight Flush": 0,
    "Flush": 0,
    "Straight": 0,
    "Quads": 0,
    "Full House": 0,
    "Trips": 0,
    "Two Pair": 0,