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})
Exemple #2
0
def test_awale():
    with createClient() as client:
        g, players = startGame(client, u'awale', 2)
        p1, p2 = players

        homes = client.command(u'awale_homes', g)
        assert homes == [
            4, 4, 4, 4, 4, 4,
            4, 4, 4, 4, 4, 4]

        client.command(u'awale_play', g, p1, 5)
        homes = client.command(u'awale_homes', g)
        assert homes == [
            4, 4, 4, 4, 0, 5,
            5, 5, 5, 4, 4, 4]
        checkAsync(client, u'awale_played', g, 5)
Exemple #3
0
def test_game():
    with createClient() as client:
        p1 = client.command(u'player_create', u'alice')
        p2 = client.command(u'player_create', u'bob')

        # test game_create
        game = client.command(u'game_create', p1, u'awale', u'label:\xe9\u20ac')
        g = game['id']
        assert game['type'] == u'awale'
        assert game['state'] == WAITING
        assert game['label'] == u'label:\xe9\u20ac'
        assert game['owner'] == p1
        assert game['players'] == [p1]
        assert game['observers'] == []

        # test game_list
        games = client.command(u'game_list')
        assert games == [game]

        # test game_info
        games = client.command(u'game_info', [g])
        assert games == [game]

        # test game_join
        client.command(u'game_join', g, p2)
        checkAsync(client, u'game_joined', g, p2)
        games = client.command(u'game_info', [g])
        game = games[0]
        assert game['players'] == [p1, p2]

        # test game_start
        client.command(u'game_start', g, p1)
        checkAsync(client, u'game_started', g)
        games = client.command(u'game_info', [g])
        game = games[0]
        assert game['state'] == PLAYING

        # test game_leave
        client.command(u'game_leave', g, p2)
        checkAsync(client, u'game_aborted', g,
            u'The player bob leaved, not enough players')