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'))
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_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)
def test_awale(): with createClient() as client: # test player_create (1) p1 = client.command(u'player_create', u'alice') players = client.command(u'player_list') players = dict((player['id'], player) for player in players) assert len(players) == 1 player1 = players[p1] assert player1['name'] == u'alice' assert player1['playing'] == [] # test player_create (2) p2 = client.command(u'player_create', u'bob') players = client.command(u'player_list') players = dict((player['id'], player) for player in players) assert len(players) == 2 assert players[p1] == player1 player2 = players[p2] assert player2['name'] == u'bob' assert player2['playing'] == []
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')
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})