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
 def test_hand_has_2_cards(self):
     from app.deck import Deck
     deck = Deck()
     deck.create()
     deck.shuffle()
     before_deal = str(deck)
     hand = Hand()
     hand.get_hand(deck)
     card1, card2 = hand.hole_cards
     assert str(card1) == before_deal[:2]
     assert str(card2) == before_deal[3:5]
     assert str(deck) == before_deal[6:]
 def test_new_hand(self):
     """The two starting cards for each player consist of their pre-flop hand. Also, called the hole cards."""
     from app.deck import Deck
     deck = Deck()
     deck.create()
     deck.shuffle()
     before_deal = str(deck)
     hand = Hand()
     hand.get_hand(deck)
     assert str(
         hand
     ) == before_deal[:
                      6]  # See the test_deck module for an explanation of the number of characters.
    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