def test_deal_unique_cards(self, three_player_game_unstarted): fake_redis = fakeredis.FakeRedis() fake_redis.set('cheers', json.dumps(three_player_game_unstarted)) bev.cache = fake_redis bev.start_game('cheers') bev.deal_hands('cheers') g = json.loads(fake_redis.get('cheers')) assert g['state'] == 'DISCARD' for player in three_player_game_unstarted['players'].keys(): assert player in g['hands'].keys() assert len(g['hands'][player]) == g['hand_size']
def test_first_discard(self, two_player_game_unstarted): fake_redis = fakeredis.FakeRedis() fake_redis.set('cheers', json.dumps(two_player_game_unstarted)) bev.cache = fake_redis bev.start_game('cheers') bev.deal_hands('cheers') g = json.loads(fake_redis.get('cheers')) player_done, all_done = bev.discard('cheers', 'sam', g['hands']['sam'][0]) assert not player_done assert not all_done assert g['state'] == 'DISCARD'
def test_start_with_two_players(self, two_player_game_unstarted): fake_redis = fakeredis.FakeRedis() fake_redis.set('cheers', json.dumps(two_player_game_unstarted)) bev.cache = fake_redis bev.start_game('cheers') g = json.loads(fake_redis.get('cheers')) assert g['state'] == 'DEAL' assert g['hand_size'] == 6 assert g['dealer'] != g['cutter'] assert g['dealer'] != g['first_to_score'] assert g['turn'] == g['dealer'] assert g['winning_score'] == 121 assert not g['jokers']
def test_all_have_discarded(self, two_player_game_unstarted): fake_redis = fakeredis.FakeRedis() fake_redis.set('cheers', json.dumps(two_player_game_unstarted)) bev.cache = fake_redis bev.start_game('cheers') bev.deal_hands('cheers') g = json.loads(fake_redis.get('cheers')) _, _ = bev.discard('cheers', 'sam', g['hands']['sam'][0]) player_done, all_done = bev.discard('cheers', 'sam', g['hands']['sam'][1]) assert player_done assert not all_done _, _ = bev.discard('cheers', 'diane', g['hands']['diane'][0]) player_done, all_done = bev.discard('cheers', 'diane', g['hands']['diane'][1]) assert player_done assert all_done g = json.loads(fake_redis.get('cheers')) assert g['state'] == 'CUT'
def start_game(msg): dealer, players = bev.start_game(msg['game'], msg['winningScore'], msg['jokers']) message = "First to {} wins! It's {}'s crib.".format( msg['winningScore'], dealer) if msg['jokers']: message += " We're playing with jokers." emit('new_message', { 'type': 'chat', 'data': message, 'nickname': 'cribby' }, room=msg['game']) emit('start_game', { 'dealer': dealer, 'players': players, 'winningScore': msg['winningScore'] }, room=msg['game'])
def play_again(msg): all_want_to_play_again = bev.play_again(msg['game'], msg['nickname']) if all_want_to_play_again: winning_score, jokers = bev.reset_game_dict(msg['game']) emit('reset_table', room=msg['game']) dealer, players = bev.start_game(msg['game'], winning_score, jokers) emit('start_game', { 'dealer': dealer, 'players': players, 'winningScore': winning_score }, room=msg['game']) message = "First to {} wins! It's {}'s crib to start.".format( winning_score, dealer) if jokers: message += " We're playing with jokers." emit('new_message', { 'type': 'chat', 'data': message, 'nickname': 'cribby' }, room=msg['game'])