コード例 #1
0
 def test_two_pair(self):
     self.assertNotEqual(score_hand(self.royal_flush_hand), '2 Pair')
     self.assertNotEqual(score_hand(self.straight_flush_hand), '2 Pair')
     self.assertNotEqual(score_hand(self.flush_hand), '2 Pair')
     self.assertNotEqual(score_hand(self.straight_hand), '2 Pair')
     self.assertNotEqual(score_hand(self.full_house_hand), '2 Pair')
     self.assertNotEqual(score_hand(self.four_of_a_kind_hand), '2 Pair')
     self.assertNotEqual(score_hand(self.three_of_a_kind_hand), '2 Pair')
     self.assertEqual(score_hand(self.two_pair_hand), '2 Pair')
     self.assertNotEqual(score_hand(self.jacks_or_better_hand), '2 Pair')
     self.assertNotEqual(score_hand(self.non_winning_hand), '2 Pair')
コード例 #2
0
 def judge(self):
     #print(self.hold_cards)
     for index in range(4, -1, -1):
         #print(index, self.hold_cards[index])
         if self.hold_cards[index] == False:
             #print("Attempting to discard #", str(index))
             #print(self.hand)
             self.hand.discard(index)
             #print("Success:\t", self.hand)
         #else:
             #print("Not attempting to discard #", str(index))
     print("Length:\t", (5 - self.hand.length()))
     for _ in range(5 - self.hand.length()):
         self.hand.draw_card(self.deck)
     # update hand GUI
     score = score_hand(self.hand)
     # to do: convert change score_hand into an array output in the format [score_name,score])
     return score
コード例 #3
0
def game_result(hold_string):
    global hold_cards
    global game_hand
    global game_deck
    print("Global card list:\t", game_hand)
    local_list = Hand()
    local_deck = copy.deepcopy(game_deck)
    hold_cards = str(hold_string).split('-')
    hold_cards_display = []
    for i in range(0, 5):
        if hold_cards[i] == 't':
            local_list.add_card(game_hand.cards[i])
            hold_cards_display.append(game_hand.cards[i])
        else:  #== 'f'
            card_to_add = local_deck.draw_card()
            local_list.add_card(card_to_add)
        hold_cards[i]
    judge_hand = []
    for i in local_list.cards:
        judge_hand.append(i)
    score = score_hand(judge_hand)
    if score != "Not a Winning Hand":
        winning_hand = True
    else:
        winning_hand = False
    display_hand = []

    for i in local_list.cards:
        display_hand.append(str(i))
    url_hand = ""
    for i in game_hand.cards:
        url_hand += str(i) + "-"
    url_hand = url_hand[0:-1]
    print("Judge hand:\t", judge_hand)
    context = {
        'cards': judge_hand,
        'score': score,
        'hold_cards': hold_cards_display,
        'winning_hand': winning_hand,
        'display_hand': display_hand,
        'url_hand': url_hand
    }
    print(context)
    return render_template('game_result.html', **context)
コード例 #4
0
def analyze(hand_string):
    cards = hand_string.split('-')
    card_list = [Card(item) for item in cards]
    score = score_hand(card_list)
    ev_list = analyze_hand(card_list)
    # get the list of cards for the highest rated play in the expected value list
    hand_to_hold = ev_list[0][0]
    hold_cards = [str(card) for card in hand_to_hold]

    plays_context = [get_play_string(row[0]) for row in ev_list]
    ev_context = [row[1] for row in ev_list]

    if score != "Not a Winning Hand":
        winning_hand = True
    else:
        winning_hand = False
    context = {'cards':cards, 'score':score, 'hold_cards':hold_cards, 'winning_hand':winning_hand, \
            'plays':plays_context, 'ev':ev_context}
    return render_template('analyze.html', **context)
コード例 #5
0
from hand import Hand
from score import score_hand
from analyze import analyze_hand

card_list = [
    Card("H", 10),
    Card("H", 11),
    Card("H", 12),
    Card("H", 13),
    Card("H", 14)
]
print("==========")
print("Testing Royal Flush")
hand = Hand(card_list)
print("Hand: {}".format(hand))
print("Score Output: {}".format(score_hand(hand)))
print("Cards to Hold: {}".format(analyze_hand(hand)))
print("")

card_list = [
    Card("H", 10),
    Card("H", 11),
    Card("H", 12),
    Card("H", 13),
    Card("H", 9)
]
print("==========")
print("Testing Straight Flush")
hand = Hand(card_list)
print("Hand: {}".format(hand))
print("Score Output: {}".format(score_hand(hand)))
コード例 #6
0
        hand = Hand()
        for _ in range(num_cards):
            hand.draw_card(deck)

        print("Select cards to hold separated by a space")
        print('Hit return to discard all')
        print(hand)
        print('[1] [2] [3] [4] [5]')
        print('')
        hold_cards = input('> ')
        if len(hold_cards) == 0:
            hold_cards = []
        else:
            hold_cards = hold_cards.split(" ")
            hold_cards = [int(val)-1 for val in hold_cards]

        for index in range(5):
            pos = 4 - index
            if pos not in hold_cards:
                hand.discard(pos)
        for _ in range(5 - len(hold_cards)):
            hand.draw_card(deck)

        print(hand)
        score = score_hand(hand)
        print(score)
        total_credits += pay_table[score] * bet * credit_value
        print('Total credits: ${0:0.2f}'.format(total_credits))
        print("Press enter to play again, q to quit:")
        command = input('> ')