示例#1
0
    def setup_method(self):
        hand = Hand(Card.strs_to_cards(TestAIPlayer.card_strs_lv2))
        self.test_ai_player_lv2 = AIPlayer(hand, 0, "")

        hand = Hand(Card.strs_to_cards(TestAIPlayer.card_strs_lv3))
        self.test_ai_player_lv3 = AIPlayer(hand, 0, "")

        self.game_state = GameState(17, 17)
        self.game_state_is_setup = False
示例#2
0
    def setup_method(self):
        hand_lv1 = Hand(Card.strs_to_cards(TestMC.card_strs_lv1))
        self.test_player_lv1 = Player(hand_lv1, 0, "")

        hand_lv2 = Hand(Card.strs_to_cards(TestMC.card_strs_lv2))
        self.test_player_lv2 = Player(hand_lv2, 0, "")

        hand_lv3 = Hand(Card.strs_to_cards(TestMC.card_strs_lv3))
        self.test_player_lv3 = Player(hand_lv3, 0, "")

        hand_lv4 = Hand(Card.strs_to_cards(TestMC.card_strs_lv4))
        self.test_player_lv4 = Player(hand_lv4, 0, "")

        self.game_state = GameState(17, 17)
示例#3
0
def setup_game(card_strs):
    hand = Hand(Card.strs_to_cards(card_strs))
    print("Starting hand:", hand)
    aiplayer = AIPlayer(hand, 0, "")
    player = Player(hand, 0, "")
    game_state = GameState(17, 17)
    return aiplayer, player, game_state
示例#4
0
def get_play_from_input(user_input):
    """returns card play based on user's input"""
    if not user_input:
        return Play.get_pass_play()
    player_card_strs = user_input.split()
    played_cards = Card.strs_to_cards(player_card_strs)
    return Play.get_play_from_cards(played_cards)
示例#5
0
 def test_prob_double_simple_three_exists(self):
     """
     100% chance of a person having a double since there is a triple
     """
     card_strs = ['3s', '4d', '4h', '4s', '5s', '5d', '6h', '6d', '7c']
     cards = Card.strs_to_cards(card_strs)
     n_cards1 = 5
     TestProbability._run_test_prob_of_occurance(cards, 2, n_cards1)
示例#6
0
 def test_prob_double_simple_hand_too_small(self):
     """
     100% chance of a person having a double since one hand is too small
     """
     card_strs = ['4d', '4h', '5h', '5c', '6h', '8d', '0c', '0h', '2c', '2h']
     cards = Card.strs_to_cards(card_strs)
     n_cards1 = 8
     TestProbability._run_test_prob_of_occurance(cards, 2, n_cards1)
示例#7
0
def get_cards_from_file(filename):
    """returns a list of cards from file"""
    card_strs = []
    with open(filename, "r") as f:
        for line in f.readlines():
            card_str = line.strip()
            card_strs.append(card_str)
    return Card.strs_to_cards(card_strs)
示例#8
0
 def test_prob_double_with_base(self):
     """tests prob of double greater than some number"""
     card_strs = ['3c', '3s', '3h', '4d', '5c', '6h', '8c', '9s', 'Jc', 'Jh', 'Ks', 'Ah', '2h']
     cards = Card.strs_to_cards(card_strs)
     n_cards1 = 6
     base_val = 5
     expected = TestProbability.prob_of_occurance_brute(cards, 2, n_cards1, base_val=base_val)
     actual = _prob_of_doubles(cards, n_cards1, base_val=base_val)
     assert actual == expected
     not_expected = TestProbability.prob_of_occurance_brute(cards, 2, n_cards1)
     assert actual != not_expected
示例#9
0
    def test_brute_is_slower(self):
        """tests that brute force is indeed slower"""
        card_strs = ['3s', '4d', '4h', '5s', '5d', '6h', '6d', '7c', '8s',
                     '9c', '0h', '0c', 'Jd', 'qs', 'Kd', 'kc', 'ah', '2c']
        cards = Card.strs_to_cards(card_strs)
        n_cards1 = 8

        time1 = time.time()
        expected = TestProbability.prob_of_occurance_brute(cards, 2, n_cards1)
        time2 = time.time()
        actual = _prob_of_doubles(cards, n_cards1)
        time3 = time.time()
        assert expected == actual
        assert time3 - time2 < time2 - time1
        print("manual time: {}\tbrute force time: {}".format(time3 - time2, time2 - time1))
示例#10
0
    def generate_game_state(computer_card_strs, unrevealed_card_strs,
                            n_cards1):
        game_state = GameState(20, 17)
        game_state.unused_cards = Card.strs_to_cards(computer_card_strs +
                                                     unrevealed_card_strs)
        game_state.used_cards = game_tools.remove_from_deck(
            get_new_ordered_deck(), game_state.unused_cards)
        game_state.player_cards = [
            len(computer_card_strs), n_cards1,
            len(unrevealed_card_strs) - n_cards1
        ]
        computer_hand = Hand([])
        computer_hand.add_cards(card_strs=computer_card_strs)
        computer = Player(computer_hand, 0, "")

        return game_state, computer
示例#11
0
    def test_prob_double_compare_two_bases(self):
        """tests prob of doubles multiple times"""
        card_strs = ['3c', '3s', '3h', '4d', '5c', '6h', '8c', '9s', 'Jc', 'Jh', 'Ks', 'Ah', '2h']
        cards = Card.strs_to_cards(card_strs)
        n_total_cards = 13
        n_cards1 = 6
        base_val_low = 5
        base_val_high = 10
        expected_low = TestProbability.prob_of_occurance_brute(cards, 2, n_cards1, base_val=base_val_low)
        actual_low = _prob_of_doubles(cards, n_cards1, base_val=base_val_low)
        assert actual_low == expected_low

        expected_high = TestProbability.prob_of_occurance_brute(cards, 2, n_cards1, base_val=base_val_high)
        actual_high = _prob_of_doubles(cards, n_cards1, base_val=base_val_high)
        assert actual_high == expected_high
        
        assert actual_low >= actual_high
示例#12
0
 def test_prob_triple_hand_too_small(self):
     """tests probability of triples with outcome of 1"""
     card_strs = ['3s', '3s', '3s', '4s', '4s','4s', '5s', '5s', '5s', '6s', '7s', '7s']
     cards = Card.strs_to_cards(card_strs)
     n_cards1 = 2
     TestProbability._run_test_prob_of_occurance(cards, 3, n_cards1)
示例#13
0
 def test_prob_triple_no_three_exists(self):
     """tests probability of triples with outcome of 0"""
     card_strs = ['3s', '3s', '4s', '4s', '5s', '5s', '6s', '7s', '7s']
     cards = Card.strs_to_cards(card_strs)
     n_cards1 = 5
     TestProbability._run_test_prob_of_occurance(cards, 3, n_cards1)
示例#14
0
 def test_prob_triple_simple(self):
     """tests probability of triples with simple inputs"""
     card_strs = ['3s', '3s', '3s', '4s', '4s','4s', '5s', '5s', '5s', '6s', '7s', '7s']
     cards = Card.strs_to_cards(card_strs)
     n_cards1 = 6
     TestProbability._run_test_prob_of_occurance(cards, 3, n_cards1)
示例#15
0
 def test_prob_double_simple(self):
     """tests prob of double with simple inputs"""
     card_strs = ['3h', '4d', '4h', '5s', '5d', '6h', '6d', '7c', '9d', '9s']
     cards = Card.strs_to_cards(card_strs)
     n_cards1 = 6
     TestProbability._run_test_prob_of_occurance(cards, 2, n_cards1)
示例#16
0
 def generate_player_from_card_strs(card_strs):
     hand = Hand(Card.strs_to_cards(card_strs))
     return Player(hand, 0, "")