def test_mille_bornes1():
    with createClient() as client:
        client.command(u'server_random_seed', 0xDEEDBEEF)

        g, players = startGame(client, u'1000 bornes', 2)
        p1, p2 = players

        # test states
        check_states(client, g,
            {u'hazard': u'', u'km': 0, u'need_roll': True},
            {u'hazard': u'', u'km': 0, u'need_roll': True})

        # test hand
        hand1 = client.command(u'mille_bornes_hand', g, p1)
        assert hand1 == [OUT_OF_GAS, KM_100, STOP, KM_75, END_OF_LIMIT, u'']
        hand2 = client.command(u'mille_bornes_hand', g, p2)
        assert hand2 == [END_OF_LIMIT, SPARE_TIME, KM_25, KM_100, SPEED_LIMIT, u'']

        # test pick + discard
        card_index, card = client.command(u'mille_bornes_pick', g, p1)
        assert card_index == 5
        assert card == KM_100
        client.command(u'mille_bornes_discard', g, p1, 3)
        checkAsync(client, u'game_turn', g, 1)
        card_index, card = client.command(u'mille_bornes_pick', g, p2)
        assert card_index == 5
        assert card == KM_75

        # test hazard (speed of limit)
        client.command(u'mille_bornes_hazard', g, p2, 4, p1)
        checkAsyncResponses(client,
            (u'mille_bornes_hazard', g, p2, 4, SPEED_LIMIT, p1),
            (u'game_turn', g, 0))
        check_states(client, g,
            {u'hazard': SPEED_LIMIT, u'km': 0, u'need_roll': True},
            {u'hazard': u'', u'km': 0, u'need_roll': True})

        # test play (end of limit)
        card_index, card = client.command(u'mille_bornes_pick', g, p1)
        assert card_index == 3
        assert card == KM_25
        client.command(u'mille_bornes_play', g, p1, 4)
        checkAsyncResponses(client,
            (u'mille_bornes_play', g, 0, END_OF_LIMIT),
            (u'game_turn', g, 1))
        check_states(client, g,
            {u'hazard': u'', u'km': 0, u'need_roll': True},
            {u'hazard': u'', u'km': 0, u'need_roll': True})
def test_mille_bornes2():
    with createClient() as client:
        client.command(u'server_random_seed', 0xDEEDBEE0)

        g, players = startGame(client, u'1000 bornes', 2)
        p1, p2 = players

        hand1 = client.command(u'mille_bornes_hand', g, p1)
        assert hand1 == [ACCIDENT, KM_200, ROLL, DRIVING_ACE, REPAIRS, u'']
        hand2 = client.command(u'mille_bornes_hand', g, p2)
        assert hand2 == [ROLL, KM_100, REPAIRS, KM_25, KM_25, u'']
        check_states(client, g,
            {u'hazard': u'', u'km': 0, u'need_roll': True},
            {u'hazard': u'', u'km': 0, u'need_roll': True})

        # play roll
        check_play(client, g, p1, 2)
        check_states(client, g,
            {u'hazard': u'', u'km': 0, u'need_roll': False},
            {u'hazard': u'', u'km': 0, u'need_roll': True})
        check_play(client, g, p2, 0)
        check_states(client, g,
            {u'hazard': u'', u'km': 0, u'need_roll': False},
            {u'hazard': u'', u'km': 0, u'need_roll': False})

        # give accident
        client.command(u'mille_bornes_pick', g, p1)
        client.command(u'mille_bornes_hazard', g, p1, 0, p2)
        checkAsyncResponses(client,
            (u'mille_bornes_hazard', g, p1, 0, ACCIDENT, p2),
            (u'game_turn', g, 1))
        check_states(client, g,
            {u'hazard': u'', u'km': 0, u'need_roll': False},
            {u'hazard': ACCIDENT, u'km': 0, u'need_roll': True})

        # use repairs
        check_play(client, g, p2, 2)
        check_states(client, g,
            {u'hazard': u'', u'km': 0, u'need_roll': False},
            {u'hazard': u'', u'km': 0, u'need_roll': True})
def check_play(client, game, player, card_index):
    client.command(u'mille_bornes_pick', game, player)
    client.command(u'mille_bornes_play', game, player, card_index)
    checkAsyncResponses(client,
        (u'mille_bornes_play', game, None, None),
        (u'game_turn', game, None))