"""
Play GROT2 game.
"""

import random

import utils


def get_move(data):
    """
    Get coordinates (start point) of next move.
    """
    return {
        'row': random.randint(0, 4),
        'col': random.randint(0, 4),
    }


def play(match_id, token, server):
    """
    Connect to game server and play rounds in the loop until end of game.
    """
    match_url = '{}/match/{}'.format(server, match_id)
    # get initial state of a match
    response = utils.json_urlopen(match_url, headers={'x-api-key': token})

    while response['code'] == 200:
        data = response['json']
        if data['moves'] == 0:
            print('Game Over!')
            break

        # make your move and get data for the next round
        response = utils.json_urlopen(
            match_url,
            headers={'x-api-key': token},
            data=get_move(data),
            method='POST',
        )

@@ -129,24 +129,295 @@
 ve.%0A    %22%22%22%0A
+    print(data%5B'preview'%5D%5B'directions'%5D, data%5B'preview'%5D%5B'points'%5D)%0A    rows_points = data%5B'board'%5D%5B'points'%5D.split('%5Cn')%0A    rows_directions = data%5B'board'%5D%5B'directions'%5D.split('%5Cn')%0A    for pair in zip(rows_directions, rows_points):%0A        print(*pair)%0A    print('')%0A%0A
     return %7B

print board state