Exemple #1
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
Exemple #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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
Exemple #10
0
 def test_double_run_of_four(self):
     card_ids = ['def8effef6', '4c8519af34', '597e4519ac', '4dfe41e461']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('276f33cf69')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'seven of hearts, eight of clubs, nine of hearts, nine of clubs, ten of clubs'
     assert len(hand.runs) == 2
     assert hand.points == 12
Exemple #11
0
 def test_fifteen_eight(self):
     card_ids = ['4f99bf15e5', '32f7615119', '4de6b73ab8', '4c8519af34']
     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
     ) == 'seven of diamonds, seven of spades, eight of hearts, eight of clubs, jack of hearts'
     assert hand.fifteens == {2: (7, 8), 4: (7, 8), 6: (7, 8), 8: (7, 8)}
     assert hand.pairs == {7: 2, 8: 2}
     assert hand.points == 12
Exemple #12
0
 def test_perfect_hand(self):
     card_ids = ['a6a3e792b4', '30e1ddb610', 'fa0873dd7d', '1d5eb77128']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('d7ca85cf5e')
     hand = Hand(cards, cut_card)
     hand.calculate_points()
     assert str(
         hand
     ) == 'five of clubs, five of spades, five of hearts, jack of diamonds, five of diamonds'
     assert hand.pairs == {5: 4}
     assert len(hand.fifteens.keys()) == 8
     assert hand._has_nobs()
     assert hand.points == 29
Exemple #13
0
 def test_crib_flush_without_cut_card(self):
     """
     A crib only has a flush if the cut card matches as well
     """
     card_ids = ['c88623fa16', '04f17d1351', '5c6bdd4fee', 'd3a2460e93']
     cards = [CARDS.get(card_id) for card_id in card_ids]
     cut_card = CARDS.get('60575e1068')
     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, king of diamonds'
     assert crib.flush_points == 0
     assert crib.points == 0
Exemple #14
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
Exemple #15
0
def score_crib(game, player):
    from app import award_points
    just_won = False

    g = json.loads(cache.get(game))
    crib_cards = [g['cards'].get(card) for card in g['crib']]
    cut_card = g['cards'].get(g['cut_card'])
    crib = Hand(crib_cards, cut_card, is_crib=True)
    crib_points = crib.calculate_points()

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

    award_points(game, player, crib_points, 'from crib', just_won)
    g['scoring_stats'][player]['c_crib'] += crib_points

    cache.set(game, json.dumps(g))
    return crib_points, just_won