Exemple #1
0
    def play_hand(self, feedback_file_name, action):
        date_time = datetime.datetime.now().strftime("%m-%d-%y %H:%M:%S")
        deck = Deck()
        deck.create()
        deck.shuffle()
        hand = Hand()
        hand.get_hand(deck)
        hand.order_hand()
        hand_type = hand.hand_type()
        position = Position()
        position.current_position(self.num_players)
        position_min = position.min_open()
        r = Range(self.hand_range)
        correct_decision, hand_percent, total_cards = r.correct_decision(
            hand_type, position_min)
        min_open_hand = r.min_open_card(position_min)
        decision = Decision(action).decision()

        if self.show_feedback:
            if decision == correct_decision:
                feedback = "Correct"  # report feedback
                self.score += 1
            else:
                feedback = "Incorrect"  # report feedback
            feedback_file_name.save_hand(self.hand_num, date_time,
                                         self.hand_range, feedback, position,
                                         position_min, min_open_hand, hand,
                                         hand_type, hand_percent, decision,
                                         correct_decision, self.score)
            self.hand_num += 1
        else:
            self.hand_num += 1

        return self.hand_num
Exemple #2
0
def flop_stage(players, deck):
    flop = Hand(maxlen=3)
    deck.burn_card()
    for i in range(3):
        flop.draw(deck)
    bet_stage(players, deck)
    return flop
Exemple #3
0
def score_hand(game, player):
    from app import award_points
    just_won = False
    next_to_score = None

    g = json.loads(cache.get(game))
    player_cards = g['played_cards'][player]
    cards = [g['cards'].get(card) for card in player_cards]
    cut_card = g['cards'].get(g['cut_card'])
    hand = Hand(cards, cut_card)
    hand_points = hand.calculate_points()

    g['players'][player] += hand_points
    if g['players'][player] >= g['winning_score']:
        just_won = True

    award_points(game, player, hand_points, 'from hand', just_won)
    g['scoring_stats'][player]['b_hand'] += hand_points

    g['scored_hands'].append(player)
    cache.set(game, json.dumps(g))

    if set(g['scored_hands']) != set(g['players'].keys()):
        next_to_score = rotate_turn(player, list(g['players'].keys()))
    return hand_points, next_to_score, just_won
 def test_suited_hand_type(self):
     from app.card import Card
     card1 = Card("8", "h")
     card2 = Card("6", "h")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     assert str(hand.hand_type()) == "86s"
     assert str(hand.hand_type()) != "86o"
Exemple #5
0
    def test_hand_figures_out_straight_flush_is_best_rank(self):
        cards = [
            Card(rank=rank, suit='Diamonds')
            for rank in ['2', '3', '4', '5', '6']
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Straight Flush'
Exemple #6
0
    def test_hand_figures_out_royal_flush_is_best_rank(self):
        cards = [
            Card(rank=rank, suit='Diamonds')
            for rank in ['10', 'Jack', 'Queen', 'King', 'Ace']
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Royal Flush'
Exemple #7
0
    def test_hand_figures_out_high_card_is_best_rank(self):
        cards = [
            Card(rank='Ace', suit='Clubs'),
            Card(rank='6', suit='Spades')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'High Card'
Exemple #8
0
    def test_hand_recieves_and_stores_cards(self):
        cards = [
            Card(rank='Queen', suit='Hearts'),
            Card(rank='3', suit='Diamonds')
        ]

        hand = Hand(cards=cards)
        assert hand.cards == cards
 def test_off_suit_hand_type(self):
     from app.card import Card
     card1 = Card("A", "s")
     card2 = Card("T", "d")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     assert str(hand.hand_type()) == "ATo"
     assert str(hand.hand_type()) != "ATs"
Exemple #10
0
    def test_hand_figures_out_flush_is_best_rank(self):
        cards = [
            Card(rank=rank, suit='Diamonds')
            for rank in ['2', '5', '8', '10', 'Ace']
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Flush'
 def test_order_1_num_1_bw_no_sort_needed(self):
     from app.card import Card
     card1 = Card("A", "c")
     card2 = Card("4", "d")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Ac" and str(oc2) == "4d"
     assert str(oc1) != "4d" and str(oc2) != "Ac"
 def test_order_2_same_no_sort_needed(self):
     from app.card import Card
     card1 = Card("J", "h")
     card2 = Card("J", "c")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Jh" and str(oc2) == "Jc"
     assert str(oc1) != "Jc" and str(oc2) != "Jh"
 def test_pair_hand_type(self):
     from app.card import Card
     card1 = Card("Q", "c")
     card2 = Card("Q", "d")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     assert str(hand.hand_type()) == "QQ"
     assert str(hand.hand_type()) != "QQs"
     assert str(hand.hand_type()) != "QQo"
     assert str(hand.hand_type()) != "QcQd"
Exemple #14
0
 def test_no_points(self):
     card_ids = ['f6571e162f', '5c6bdd4fee', 'ace1293f8a', '110e6e5b19']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('32f7615119')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'ten of diamonds, four of spades, two of hearts, jack of clubs, seven of spades'
     assert hand.points == 0
 def test_order_1_num_1_bw_sort_needed(self):
     from app.card import Card
     card1 = Card("2", "h")
     card2 = Card("K", "s")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Ks" and str(oc2) == "2h"
     assert str(oc1) != "2h" and str(oc2) != "Ks"
     assert str(card1) == "2h" and str(card2) == "Ks"
 def test_order_2_bw_sort_needed(self):
     from app.card import Card
     card1 = Card("T", "d")
     card2 = Card("K", "c")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Kc" and str(oc2) == "Td"
     assert str(oc1) != "Td" and str(oc2) != "Kc"
     assert str(card1) == "Td" and str(card2) == "Kc"
 def test_order_2_same_sort_needed(self):
     """This really never requires a sort; however, it will still be sorted alphabetically."""
     from app.card import Card
     card1 = Card("A", "s")
     card2 = Card("A", "d")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Ad" and str(oc2) == "As"
     assert str(oc1) != "As" and str(oc2) != "Ad"
     assert str(card1) == "As" and str(card2) == "Ad"
Exemple #18
0
    def test_hand_figures_out_straight_is_best_rank(self):
        cards = [
            Card(rank='3', suit='Hearts'),
            Card(rank='4', suit='Spades'),
            Card(rank='5', suit='Hearts'),
            Card(rank='6', suit='Diamonds'),
            Card(rank='7', suit='Clubs')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Straight'
Exemple #19
0
 def test_crib_flush_with_cut_card(self):
     card_ids = ['c88623fa16', '04f17d1351', '5c6bdd4fee', 'd3a2460e93']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('32f7615119')
     crib = Hand(cards, cut_card, is_crib=True)
     crib.calculate_points()
     assert str(
         crib
     ) == 'six of spades, three of spades, four of spades, ten of spades, seven of spades'
     assert crib.flush_points == 5
     assert crib.points == 5
Exemple #20
0
    def test_hand_figures_out_two_pair_is_best_rank(self):
        cards = [
            Card(rank='Ace', suit='Spades'),
            Card(rank='9', suit='Clubs'),
            Card(rank='7', suit='Diamonds'),
            Card(rank='Ace', suit='Diamonds'),
            Card(rank='7', suit='Hearts')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Two Pair'
Exemple #21
0
    def test_hand_figures_out_single_pair_is_best_rank(self):
        cards = [
            Card(rank='Jack', suit='Spades'),
            Card(rank='4', suit='Clubs'),
            Card(rank='7', suit='Diamonds'),
            Card(rank='King', suit='Diamonds'),
            Card(rank='7', suit='Hearts')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Pair'
Exemple #22
0
 def test_fifteen_two(self):
     card_ids = ['f6571e162f', '30e1ddb610', 'ace1293f8a', '4dfe41e461']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('32f7615119')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'ten of diamonds, five of spades, two of hearts, nine of clubs, seven of spades'
     assert hand.fifteens == {2: (5, 10)}
     assert hand.points == 2
Exemple #23
0
 def test_fifteen_four(self):
     card_ids = ['f6571e162f', '30e1ddb610', 'c88523b677', '4dfe41e461']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('ace1293f8a')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'ten of diamonds, five of spades, six of hearts, nine of clubs, two of hearts'
     assert hand.fifteens == {2: (5, 10), 4: (6, 9)}
     assert hand.points == 4
Exemple #24
0
 def test_fifteen_six(self):
     card_ids = ['f6571e162f', '30e1ddb610', 'c88523b677', 'ae2caea4bb']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('56594b3880')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'ten of diamonds, five of spades, six of hearts, king of clubs, jack of hearts'
     assert hand.fifteens == {2: (5, 10), 4: (5, 10), 6: (5, 10)}
     assert hand.points == 6
Exemple #25
0
 def test_one_run(self):
     card_ids = ['def8effef6', '4dfe41e461', '4c8519af34', 'ace1293f8a']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('110e6e5b19')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'seven of hearts, nine of clubs, eight of clubs, two of hearts, jack of clubs'
     assert len(hand.runs) == 1
     assert hand.points == 5
Exemple #26
0
 def test_two_pairs(self):
     card_ids = ['f6571e162f', 'd3a2460e93', 'ace1293f8a', 'd1c9fde8ef']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('32f7615119')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'ten of diamonds, ten of spades, two of hearts, two of clubs, seven of spades'
     assert hand.pairs == {10: 2, 2: 2}
     assert hand.points == 4
Exemple #27
0
    def test_hand_figures_out_full_house_is_best_rank(self):
        cards = [
            Card(rank='3', suit='Clubs'),
            Card(rank='3', suit='Hearts'),
            Card(rank='3', suit='Diamonds'),
            Card(rank='9', suit='Spades'),
            Card(rank='9', suit='Diamonds')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Full House'
Exemple #28
0
 def test_hand_flush_without_cut_card(self):
     card_ids = ['c88623fa16', '04f17d1351', '5c6bdd4fee', 'd3a2460e93']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('60575e1068')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'six of spades, three of spades, four of spades, ten of spades, king of diamonds'
     assert hand.flush_points == 4
     assert hand.points == 4
Exemple #29
0
    def test_hand_figures_out_four_of_a_kind_is_best_rank(self):
        cards = [
            Card(rank='7', suit='Spades'),
            Card(rank='King', suit='Clubs'),
            Card(rank='7', suit='Clubs'),
            Card(rank='7', suit='Diamonds'),
            Card(rank='7', suit='Hearts')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Four of a Kind'
Exemple #30
0
 def test_four_runs(self):
     card_ids = ['def8effef6', '4dfe41e461', '4c8519af34', '597e4519ac']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('ce46b344a3')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'seven of hearts, nine of clubs, eight of clubs, nine of hearts, eight of spades'
     assert len(hand.runs) == 4
     assert hand.points == 20