<commit_before>#
# Copyright 2017 <NAME> (<EMAIL>). All rights reserved
#

import numpy as np

LOSE = -1
WIN = 1
NEUTRAL = 0

EMPTY=0.5
NAUGHT=0.0
CROSS= 1.0

class Board:
    DIRS = []
    for k in range(-1,2):
        for j in range(-1,2):
            if(k!=0 or j!= 0):
                DIRS.append((k,j))

    def __init__(self, s= None):
        self.state = s
        if not self.state:
            self.state = np.ndarray(shape=(1,9), dtype=float)[0]
            self.reset()

    def reset(self) :
        self.state.fill(EMPTY)

    def num_empty(self):
        return np.count_nonzero(self.state == EMPTY)

    def random_empty_spot(self):
        index = np.random.randint(self.num_empty())
        for i in range(9):
            if self.state[i] == EMPTY:
                if index == 0:
                    return i
                else:
                    index = index-1

    def is_legal(self, pos):
        return self.state[pos] == EMPTY

    def move(self, position, type):
        if self.state[position]!=EMPTY:
            print('Illegal move')
            raise ValueError("Invalid move")
#            return self.state, ILLEGAL, True

        self.state[position] = type

        if(self.check_win() != EMPTY):
            return self.state, WIN, True

        if(self.num_empty()==0):
            return self.state, NEUTRAL, True

        return self.state, NEUTRAL, False

    def apply_dir(self, pos, dir):
        row = pos / 3
        col = pos % 3
        row += dir[0]<commit_msg>Made Python 3 compatible<commit_after>#
# Copyright 2017 <NAME> (<EMAIL>). All rights reserved
#

import numpy as np

LOSE = -1
WIN = 1
NEUTRAL = 0

EMPTY=0.5
NAUGHT=0.0
CROSS= 1.0

class Board:
    DIRS = []
    for k in range(-1,2):
        for j in range(-1,2):
            if(k!=0 or j!= 0):
                DIRS.append((k,j))

    def __init__(self, s= None):
        self.state = s
        if not self.state:
            self.state = np.ndarray(shape=(1,9), dtype=float)[0]
            self.reset()

    def reset(self) :
        self.state.fill(EMPTY)

    def num_empty(self):
        return np.count_nonzero(self.state == EMPTY)

    def random_empty_spot(self):
        index = np.random.randint(self.num_empty())
        for i in range(9):
            if self.state[i] == EMPTY:
                if index == 0:
                    return i
                else:
                    index = index-1

    def is_legal(self, pos):
        return self.state[pos] == EMPTY

    def move(self, position, type):
        if self.state[position]!=EMPTY:
            print('Illegal move')
            raise ValueError("Invalid move")
#            return self.state, ILLEGAL, True

        self.state[position] = type

        if(self.check_win() != EMPTY):
            return self.state, WIN, True

        if(self.num_empty()==0):
            return self.state, NEUTRAL, True

        return self.state, NEUTRAL, False

    def apply_dir(self, pos, dir):
        row = pos // 3
        col = pos % 3
        row += dir[0]
{'fraction_non_alphanumeric': 0.1263192612137203, 'fraction_numerical': 0.01945910290237467, 'mean_word_length': 1.710455764075067, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '563643', 'n_tokens_mistral': 1043, 'n_tokens_neox': 976, 'n_words': 258}