<commit_before>from __future__ import division, print_function, unicode_literals
from capstone.game import Connect4 as C4


def load_instance(instance):
    '''
    Loads a position from the Connect 4 database:

    https://archive.ics.uci.edu/ml/machine-learning-databases/connect-4/connect-4.names

    Returns a tuple with an instance of a Connect4 game with that position, and the
    outcome for the first player under perfect play.
    '''
    tokens = instance.split(',')
    cells = tokens[:-1]
    outcome = tokens[-1]
    cell_map = {'x': 'X', 'o': 'O', 'b': '-'}
    board = [[' '] * C4.COLS for row in range(C4.ROWS)]
    for ix, cell in enumerate(cells):
        row = C4.ROWS - (ix % C4.ROWS) - 1
        col = ix // C4.ROWS
        board[row][col] = cell_map[cell]
    return C4(board), outcome

# instance = 'b,b,b,b,b,b,b,b,b,b,b,b,x,o,b,b,b,b,x,o,x,o,x,o,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,win'
# game, outcome = load_instance(instance)
# print(game)
# print(outcome)
<commit_msg>cleanup<commit_after>from __future__ import division, print_function, unicode_literals
from capstone.game import Connect4 as C4


def load_instance(instance):
    '''
    Loads a position from the Connect 4 database:

    https://archive.ics.uci.edu/ml/machine-learning-databases/connect-4/connect-4.names

    Returns a tuple with an instance of a Connect4 game with that position, and the
    outcome for the first player under perfect play.
    '''
    tokens = instance.split(',')
    cells = tokens[:-1]
    outcome = tokens[-1]
    cell_map = {'x': 'X', 'o': 'O', 'b': '-'}
    board = [[' '] * C4.COLS for row in range(C4.ROWS)]
    for ix, cell in enumerate(cells):
        row = C4.ROWS - (ix % C4.ROWS) - 1
        col = ix // C4.ROWS
        board[row][col] = cell_map[cell]
    return C4(board), outcome

{'fraction_non_alphanumeric': 0.15041322314049588, 'fraction_numerical': 0.01652892561983471, 'mean_word_length': 3.1939953810623556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2448507', 'n_tokens_mistral': 670, 'n_tokens_neox': 653, 'n_words': 171}