<commit_before>from chess_move import ChessMove
from chess_position import ChessPosition

import chess.uci

# This object is created purely for testing purposes as of now, but might exist permanently in this class later
board = chess.Board()

# Setup Stockfish engine
engine = chess.uci.popen_engine("/stockfish_8_x32")
engine.uci()


# Give a ChessMove object to the third-party library, push it to board if ok
def hand_off(move):
    if isinstance(move, ChessMove):
        try:
            board.push_uci(move.__str__())
            engine.position(board)
        except ValueError:
            print('\033[91m' + "Invalid move: " + move.__str__() + "!" + '\033[0m')
    else:
        raise TypeError("Parameter of hand_off must be of type ChessMove")


# Asks Chess Library for a move, pushes it to board, and returns it as a ChessMove object
def get_move():
    command = engine.go(movetime=2000, async_callback=True)
    best_move, ponder = command.result()
    bm = str(best_move)

    # Converts UCI protocol to ChessPosition via splicing
    init = ChessPosition(str(bm[:1]), int(bm[1:-2]))
    final = ChessPosition(str(bm[2:-1]), int(bm[3:]))

    board.push_uci(str(best_move))
    engine.position(board)

    return ChessMove(init, final)<commit_msg>Running code from chess_library will produce a rough test of actual chess game<commit_after>from chess_move import ChessMove
from chess_position import ChessPosition

import chess.uci

# This object is created purely for testing purposes as of now, but might exist permanently in this class later
board = chess.Board()

# Setup Stockfish engine
engine = chess.uci.popen_engine("/stockfish_8_x32")
engine.uci()


# Give a ChessMove object to the third-party library, push it to board if ok
def hand_off(move):
    if isinstance(move, ChessMove):
        try:
            board.push_uci(move.__str__())
            engine.position(board)
        except ValueError:
            print('\033[91m' + "Invalid move: " + move.__str__() + "!" + '\033[0m')
            return False
    elif isinstance(move, str):
        try:
            board.push_uci(move)
            engine.position(board)
        except ValueError:
            print('\033[91m' + "Invalid move: " + move + "!" + '\033[0m')
            return False
    else:
        raise TypeError("Parameter of hand_off must be of type ChessMove or String")
    return True


# Asks Chess Library for a move, pushes it to board, and returns it as a ChessMove object
def get_move():
    command = engine.go(movetime=2000, async_callback=True)
    best_move, ponder = command.result()
    bm = str(best_move)

    # Converts UCI protocol to ChessPosition via splicing
    init = ChessPosition(str(bm[:1]), int(bm[1:-2]))
    final = ChessPosition(str(bm[2:-1]), int(bm[3:]))

    board.push_uci(str(best_move))
    engine.position(board)

    return ChessMove(init, final)


# Self explanatory
def is_game_over():
    return board.is_game_over();


# Test code. Very rough but it works
while not is_game_over():
    x = get_move()
    print(x.__str__())
    y = False
    while not y:
        y = hand_off(input("Enter move: "))
{'fraction_non_alphanumeric': 0.1055148230793752, 'fraction_numerical': 0.01689512272872171, 'mean_word_length': 3.252032520325203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1726394', 'n_tokens_mistral': 1014, 'n_tokens_neox': 957, 'n_words': 301}