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"
示例#2
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
 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"
 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"
    def play_hand(self, feedback_file_name):
        date_time = datetime.datetime.now().strftime("%m-%d-%y %H:%M:%S")
        print("Hand number: " + str(self.hand_num))

        deck = Deck()
        deck.create()
        deck.shuffle()

        hand = Hand()
        hand.get_hand(deck)
        print(hand)

        hand.order_hand()
        hand_type = hand.hand_type()

        position = Position()
        position.current_position(self.num_players)
        print(position)

        position_min = position.min_open()

        r = Range(self.hand_range)
        correct_decision, hand_percent, total_cards = r.correct_decision(
            hand_type, position_min)
        # Leaving the following several print statements for reference in case someone else isn't that familiar with hand range calculations.
        # print(correct_decision)
        # print(hand_percent)
        # print(total_cards)  # To confirm the hand percentage is correct: total_cards / 1326 = hand_percent

        min_open_hand = r.min_open_card(position_min)
        # print(min_open_hand)

        action = int(input("What is your decision? (4=Open, 6=Fold): ")
                     )  # For faster keyboard input
        decision = Decision(action).decision()

        if decision != "stop":
            if self.show_feedback:
                if decision == correct_decision:
                    # screen feedback
                    print(
                        "Good job! You should", correct_decision,
                        "because you want to play the top {0:.2f}".format(
                            position_min * 100) +
                        "% of your range; which ends at " +
                        str(min_open_hand) + ".\n" + str(hand) +
                        "is in the top {0:.2f}".format(hand_percent * 100) +
                        "% of starting hands for the " + self.hand_range +
                        " range.")
                    feedback = "Correct"  # report feedback
                    self.score += 1
                else:
                    print(
                        "Sorry, you should", correct_decision,
                        "because you want to play the top {0:.2f}".format(
                            position_min * 100) +
                        "% of your range; which ends at " +
                        str(min_open_hand) + ".\n" + str(hand) +
                        "is in the top {0:.2f}".format(hand_percent * 100) +
                        "% of starting hands for the " + self.hand_range +
                        " range.")
                    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
                print("Score: " + str(self.score) + "\n")
            else:
                self.hand_num += 1
                print()
        else:
            print("Thanks for playing.")

        return action