コード例 #1
0
    def test_thirtyone(self):
        """
        Verify two points for 31
        """
        fake_redis = fakeredis.FakeRedis()
        game_dict = {
            'cards': CARDS,
            'hands': {
                'kathy': ['6d95c18472', 'c6f4900f82'],
                'tom': ['ace1293f8a']
            },
            'pegging': {
                'cards': ['4de6b73ab8', 'f6571e162f',
                          'c88523b677'],  # eight, ten, six
                'last_played': 'tom',
                'passed': [],
                'run': [],
                'total': 24
            },
            'players': {
                'tom': 0,
                'kathy': 0
            },
            'played_cards': {
                'kathy': ['f6571e162f'],
                'tom': ['4de6b73ab8', 'c88523b677']
            },
            'scoring_stats': {
                'tom': {
                    'a_play': 0,
                    'b_hand': 0,
                    'c_crib': 0
                },
                'kathy': {
                    'a_play': 0,
                    'b_hand': 0,
                    'c_crib': 0
                }
            },
            'state': 'PLAY',
            'turn': 'kathy',
            'winning_score': 121,
        }

        fake_redis.set('test', json.dumps(game_dict))
        bev.cache = fake_redis
        seven_of_clubs = 'c6f4900f82'
        just_won, points, points_source = bev.score_play(
            'test', 'kathy', seven_of_clubs)
        assert not just_won
        bev.record_play('test', 'kathy', seven_of_clubs)
        g = json.loads(fake_redis.get('test'))
        assert set(g['pegging']['cards']) == set(
            ['4de6b73ab8', 'f6571e162f', 'c88523b677', 'c6f4900f82'])
        assert g['hands']['kathy'] == ['6d95c18472']
        assert g['players']['kathy'] == 2
        assert g['pegging']['total'] == 31
コード例 #2
0
    def test_run_of_three(self):
        """
        test run of three scores three points
        """
        fake_redis = fakeredis.FakeRedis()
        game_dict = {
            'cards': CARDS,
            'hands': {
                'kathy': ['6d95c18472', 'c6f4900f82'],
                'tom': ['ace1293f8a']
            },
            'pegging': {
                'cards': ['4de6b73ab8', 'c88523b677'],  # eight, six
                'last_played': 'tom',
                'passed': [],
                'run': [],
                'total': 14
            },
            'players': {
                'tom': 0,
                'kathy': 0
            },
            'played_cards': {
                'kathy': ['32f7615119'],
                'tom': ['4f99bf15e5', 'def8effef6']
            },
            'scoring_stats': {
                'tom': {
                    'a_play': 0,
                    'b_hand': 0,
                    'c_crib': 0
                },
                'kathy': {
                    'a_play': 0,
                    'b_hand': 0,
                    'c_crib': 0
                }
            },
            'state': 'PLAY',
            'turn': 'kathy',
            'winning_score': 121,
        }

        fake_redis.set('test', json.dumps(game_dict))
        bev.cache = fake_redis
        seven_of_clubs = 'c6f4900f82'
        just_won, points, points_source = bev.score_play(
            'test', 'kathy', seven_of_clubs)
        assert not just_won
        bev.record_play('test', 'kathy', seven_of_clubs)
        g = json.loads(fake_redis.get('test'))
        assert set(g['pegging']['cards']) == set(
            ['4de6b73ab8', 'c88523b677', 'c6f4900f82'])  # all the sevens
        assert g['hands']['kathy'] == ['6d95c18472']
        assert g['pegging']['total'] == 21
        assert g['players']['kathy'] == 3
コード例 #3
0
    def test_four_of_a_kind(self):
        fake_redis = fakeredis.FakeRedis()
        game_dict = {
            'cards': CARDS,
            'hands': {
                'kathy': ['6d95c18472', 'c6f4900f82'],
                'tom': ['ace1293f8a']
            },
            'pegging': {
                'cards': ['32f7615119', '4f99bf15e5',
                          'def8effef6'],  # seven of spades, diamonds, hearts
                'last_played': 'tom',
                'passed': [],
                'run': [],
                'total': 21
            },
            'players': {
                'tom': 6,
                'kathy': 2
            },
            'played_cards': {
                'kathy': ['32f7615119'],
                'tom': ['4f99bf15e5', 'def8effef6']
            },
            'scoring_stats': {
                'tom': {
                    'a_play': 0,
                    'b_hand': 0,
                    'c_crib': 0
                },
                'kathy': {
                    'a_play': 0,
                    'b_hand': 0,
                    'c_crib': 0
                }
            },
            'state': 'PLAY',
            'turn': 'kathy',
            'winning_score': 121,
        }

        fake_redis.set('test', json.dumps(game_dict))
        bev.cache = fake_redis
        seven_of_clubs = 'c6f4900f82'
        just_won, points, points_source = bev.score_play(
            'test', 'kathy', seven_of_clubs)
        assert not just_won
        bev.record_play('test', 'kathy', seven_of_clubs)
        g = json.loads(fake_redis.get('test'))
        assert set(g['pegging']['cards']) == set(
            ['32f7615119', '4f99bf15e5', 'def8effef6',
             'c6f4900f82'])  # all the sevens
        assert g['hands']['kathy'] == ['6d95c18472']
        assert g['pegging']['total'] == 28
        assert g['players']['kathy'] == 14
コード例 #4
0
    def test_fifteen_two(self):
        fake_redis = fakeredis.FakeRedis()
        game_dict = {
            'cards': CARDS,
            'hands': {
                'kathy': ['6d95c18472', 'c6f4900f82'],
                'tom': ['ace1293f8a']
            },
            'pegging': {
                'cards': ['4de6b73ab8'],  # eight of hearts
                'last_played': 'tom',
                'passed': [],
                'run': [],
                'total': 8
            },
            'players': {
                'tom': 0,
                'kathy': 0
            },
            'played_cards': {
                'kathy': [],
                'tom': []
            },
            'scoring_stats': {
                'tom': {
                    'a_play': 0,
                    'b_hand': 0,
                    'c_crib': 0
                },
                'kathy': {
                    'a_play': 0,
                    'b_hand': 0,
                    'c_crib': 0
                }
            },
            'state': 'PLAY',
            'turn': 'kathy',
            'winning_score': 121,
        }

        fake_redis.set('test', json.dumps(game_dict))
        bev.cache = fake_redis
        seven_of_clubs = 'c6f4900f82'
        just_won, points, points_source = bev.score_play(
            'test', 'kathy', seven_of_clubs)
        assert not just_won
        bev.record_play('test', 'kathy', seven_of_clubs)
        g = json.loads(fake_redis.get('test'))
        assert g['players']['kathy'] == 2
        assert g['pegging']['total'] == 15
        assert set(g['pegging']['cards']) == set(['4de6b73ab8', 'c6f4900f82'])
        assert g['hands']['kathy'] == ['6d95c18472']
コード例 #5
0
def peg_round_action(msg):
    """
    Handles the playing of a card as well as passing on playing
    :param message:
    :return:
    """
    if 'card_played' in msg.keys():
        total = bev.get_pegging_total(msg['game'])
        if bev.get_card_value(msg['game'], msg['card_played']) > (31 - total):
            emit('invalid_card', {'card': msg['card_played']})
            return

        if msg['player'] != bev.get_current_turn(msg['game']):
            emit('invalid_card', {'card': msg['card_played']})
            return

        just_won, points_scored, points_source = bev.score_play(
            msg['game'], msg['player'], msg['card_played'])

        new_total = bev.record_play(msg['game'], msg['player'],
                                    msg['card_played'])
        card_text = card_text_from_id(msg['card_played'])
        message = '{} played {}. <b>({})</b>'.format(msg['player'], card_text,
                                                     new_total)

        emit('new_message', {
            'type': 'action',
            'data': message
        },
             room=msg['game'])
        emit('show_card_played', {
            'nickname': msg['player'],
            'card': msg['card_played']
        },
             room=msg['game'])

        if points_scored > 0:
            reason = ', '.join(ps for ps in sorted(points_source))
            award_points(msg['game'], msg['player'], points_scored, reason,
                         just_won)
        if just_won:
            return

    else:
        bev.record_pass(msg['game'], msg['player'])
        emit('new_message', {
            'type': 'action',
            'data': '{} passed.'.format(msg['player'])
        },
             room=msg['game'])

    next_player, go_point_wins = bev.next_player(msg['game'])
    if go_point_wins:
        return
    next_action = bev.get_player_action(msg['game'], next_player)
    if next_action == 'SCORE':
        emit('new_message', {
            'type':
            'chat',
            'data':
            "Time to score everyone's hand! {} goes first.".format(
                next_player),
            'nickname':
            'cribby'
        },
             room=msg['game'])

    emit('send_turn', {
        'player': next_player,
        'action': next_action
    },
         room=msg['game'])