Пример #1
0
def get_player_action(game, player):
    g = json.loads(cache.get(game))
    if g['state'] == 'SCORE':
        next_action = 'SCORE'
    else:
        if g['pegging']['total'] == 31:
            return 'PLAY'
        card_values = [
            g['cards'][card]['value'] for card in g['hands'][player]
        ]
        next_action = play_or_pass(card_values, g['pegging']['total'])

    cache.set(game, json.dumps(g))
    return next_action
Пример #2
0
 def test_must_play_when_multiple_cards(self):
     cards = ['4', '6', '9']  # four of hearts, six of clubs, nine of diamonds
     assert play_or_pass(cards, 27) == 'PLAY'
Пример #3
0
 def test_all_cards_can_play_when_total_is_twentyone(self):
     for id, card in CARDS.items():
         assert play_or_pass([card['value']], 21) == 'PLAY'
Пример #4
0
    def test_play_or_pass_base_case(self):
        cards = ['1']  # ace of diamonds
        assert play_or_pass(cards, 30) == 'PLAY'

        cards = ['2']  # two of diamonds
        assert play_or_pass(cards, 30) == 'PASS'