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_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_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_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_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_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"
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