Exemplo n.º 1
0
def test_gnuchess():
    with createClient() as client:
        g, players = startGame(client, u'chess', 2)
        p1, p2 = players

        board = client.command(u'chess_board', g)
        assert ''.join(board) == (
            'RNBQKBNR'
            'PPPPPPPP'
            '        '
            '        '
            '        '
            '        '
            'pppppppp'
            'rnbqkbnr'
        )

        # Test white
        moves = client.command(u'chess_possible_moves', g, 'a2')
        assert set(moves) == set(('a3', 'a4'))
        moves = client.command(u'chess_possible_moves', g, 'b1')
        assert set(moves) == set(('a3', 'c3'))

        # Test black
        moves = client.command(u'chess_possible_moves', g, 'c7')
        assert set(moves) == set(('c6', 'c5'))
        moves = client.command(u'chess_possible_moves', g, 'g8')
        assert set(moves) == set(('f6', 'h6'))
Exemplo n.º 2
0
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})
Exemplo n.º 3
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)
Exemplo n.º 4
0
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})