<commit_before>#!/usr/bin/env python
"""Python implementation of chess, main entry point."""
import json
from board import Board
from piece import Piece
from move import Move
#from python_chess.chess_engine import pick_move
from utils import (shout, write_log, cell_ref_to_pos,
                   pos_to_cell_ref, format_msg, VERBOSE)

# constants
LOGGING = False
LOG = ''
MOVE_INSTRUCTIONS = format_msg("\nTo specify a move enter the cell reference " +
    "for the piece want to move and the cell reference for the new location. " +
    "The first two characters of your prompt entry are used to identify " +
    "the current cell and the last two for the new cell e.g. to move from " +
    "A2 to A4 you could enter 'A2, A4' or use shorthand of 'a2a4'.")


class Game(object):
    """Top level class, the game object contains all of the other 
    class instances such as the pieces, the board etc."""
    PIECE_CODES = {'K': 'king', 'Q': 'queen', 'R':'rook',
                   'B':'bishop', 'N': 'knight', 'p': 'pawn'}
    TEAMS = {'w': 'white', 'b': 'black'}

    # describe piece positions by rank (row from botton up) and file (col)
    # used to instantiate Board and Piece classes
    START_POSITIONS = { 8: {'A': 'bR1', 'B': 'bN1', 'C': 'bB1', 'D': 'bQ' , 
                            'E': 'bK' , 'F': 'bB2', 'G': 'bN2', 'H': 'bR2'},
                        7: {'A': 'bp1', 'B': 'bp2', 'C': 'bp3', 'D': 'bp4', 
                            'E': 'bp5', 'F': 'bp6', 'G': 'bp7', 'H': 'bp8'},
                        6: {'A': False, 'B': False, 'C': False, 'D': False, 
                            'E': False, 'F': False, 'G': False, 'H': False},
                        5: {'A': False, 'B': False, 'C': False, 'D': False, 
                            'E': False, 'F': False, 'G': False, 'H': False},
                        4: {'A': False, 'B': False, 'C': False, 'D': False, 
                            'E': False, 'F': False, 'G': False, 'H': False},
                        3: {'A': False, 'B': False, 'C': False, 'D': False, 
                            'E': False, 'F': False, 'G': False, 'H': False},
                        2: {'A': 'wp1', 'B': 'wp2', 'C': 'wp3', 'D': 'wp4', 
                            'E': 'wp5', 'F': 'wp6', 'G': 'wp7', 'H': 'wp8'},
                        1: {'A': 'wR1', 'B': 'wN1', 'C': 'wB1', 'D': 'wQ' , 
                            'E': 'wK' , 'F': 'wB2', 'G': 'wN2', 'H': 'wR2'}
                      }

    move_dict = {'king':   [[1, 1], [1, 0], [1, -1], [0, 1],
                            [0, -1], [-1, 1], [-1, 0], [-1, -1]], 
                 'rook':    [[i, 0] for i in range(1,9)] + \
                            [[0, i] for i in range(1,9)] + \
                            [[i*-1, 0] for i in range(1,9)] + \
                            [[0, i*-1] for i in range(1,9)], 
                 'bishop':  [[i, i] for i in range(1,9)] + \
                            [[i, i*-1] for i in range(1,9)] + \
                            [[i*-1, i] for i in range(1,9)] + \
                            [[i*-1, i*-1] for i in range(1,9)],  
                 'knight': [[2, 1], [2, -1], 
                            [1, 2], [1, -2], 
                            [-1, 2], [-1, -2], 
                            [-2, 1], [-2, -1]], 
                 'pawn':   [[1, 1, 'on_take'], 
                            [1, -1, 'on_take'], 
                            [1, 1, 'en_passant'], 
                            [1, -1, 'en_passant'], 
                            [1, 0], 
                            [2, 0, 'on_first']]
                 }
    move_dict['queen'] = move_dict['rook']+move_dict['bishop']

    def __init__(self):
        """Initialise game object and create required member objects"""
                     
        self.board = Board(Game.START_POSITIONS)
        self.pieces = self.__create_pieces(Game.move_dict)<commit_msg>refactor of move_dict<commit_after>#!/usr/bin/env python
"""Python implementation of chess, main entry point."""
import json
from board import Board
from piece import Piece
from move import Move
#from python_chess.chess_engine import pick_move
from utils import (shout, write_log, cell_ref_to_pos,
                   pos_to_cell_ref, format_msg, VERBOSE)

# constants
LOGGING = False
LOG = ''
MOVE_INSTRUCTIONS = format_msg("\nTo specify a move enter the cell reference " +
    "for the piece want to move and the cell reference for the new location. " +
    "The first two characters of your prompt entry are used to identify " +
    "the current cell and the last two for the new cell e.g. to move from " +
    "A2 to A4 you could enter 'A2, A4' or use shorthand of 'a2a4'.")


class Game(object):
    """Top level class, the game object contains all of the other 
    class instances such as the pieces, the board etc."""
    PIECE_CODES = {'K': 'king', 'Q': 'queen', 'R':'rook',
                   'B':'bishop', 'N': 'knight', 'p': 'pawn'}
    TEAMS = {'w': 'white', 'b': 'black'}

    # describe piece positions by rank (row from bottom up) and file (col)
    # used to instantiate Board and Piece classes
    START_POSITIONS = { 8: {'A': 'bR1', 'B': 'bN1', 'C': 'bB1', 'D': 'bQ' , 
                            'E': 'bK' , 'F': 'bB2', 'G': 'bN2', 'H': 'bR2'},
                        7: {'A': 'bp1', 'B': 'bp2', 'C': 'bp3', 'D': 'bp4', 
                            'E': 'bp5', 'F': 'bp6', 'G': 'bp7', 'H': 'bp8'},
                        6: {'A': False, 'B': False, 'C': False, 'D': False, 
                            'E': False, 'F': False, 'G': False, 'H': False},
                        5: {'A': False, 'B': False, 'C': False, 'D': False, 
                            'E': False, 'F': False, 'G': False, 'H': False},
                        4: {'A': False, 'B': False, 'C': False, 'D': False, 
                            'E': False, 'F': False, 'G': False, 'H': False},
                        3: {'A': False, 'B': False, 'C': False, 'D': False, 
                            'E': False, 'F': False, 'G': False, 'H': False},
                        2: {'A': 'wp1', 'B': 'wp2', 'C': 'wp3', 'D': 'wp4', 
                            'E': 'wp5', 'F': 'wp6', 'G': 'wp7', 'H': 'wp8'},
                        1: {'A': 'wR1', 'B': 'wN1', 'C': 'wB1', 'D': 'wQ' , 
                            'E': 'wK' , 'F': 'wB2', 'G': 'wN2', 'H': 'wR2'}
                      }

    move_dict = {'king':   [[i, j] for i in range(-1,2) for j in range(-1,2) if i != 0 or j != 0],
                 'rook':   [[i, 0] for i in range(-8,9) if i != 0] +
                           [[0, i] for i in range(-8,9) if i != 0],
                 'bishop': [[i, i] for i in range(-8,9) if i != 0] +
                           [[i, i*-1] for i in range(-8,9) if i != 0],
                 'knight': [[i, j] for i in range(-2,3) for j in range(-2,3) if abs(i)+abs(j) == 3],
                 'pawn':   [[1, i, msg] for i in [-1,1] for msg in ['on_take', 'en_passant']] +
                           [[2, 0, 'on_first'], [1, 0]]
                 }
    move_dict['queen'] = move_dict['rook']+move_dict['bishop']

    def __init__(self):
        """Initialise game object and create required member objects"""
                     
        self.board = Board(Game.START_POSITIONS)
        self.pieces = self.__create_pieces(Game.move_dict)
{'fraction_non_alphanumeric': 0.1900769653655855, 'fraction_numerical': 0.02570093457943925, 'mean_word_length': 1.5952211126961484, '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': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1573229', 'n_tokens_mistral': 2539, 'n_tokens_neox': 2429, 'n_words': 818}