From e07a195bdd87932b9d00d3d680a9a5a747359566 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 9 Jul 2025 15:50:50 +0200 Subject: initial commit --- chessconf.py | 220 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 chessconf.py (limited to 'chessconf.py') diff --git a/chessconf.py b/chessconf.py new file mode 100644 index 0000000..6b1d296 --- /dev/null +++ b/chessconf.py @@ -0,0 +1,220 @@ +# _________ .__ _________ _____.__ +# \_ ___ \| |__ ____ ______ _____\_ ___ \ ____ _____/ ____\__| ____ +# / \ \/| | \_/ __ \ / ___// ___/ \ \/ / _ \ / \ __\| |/ ___\ +# \ \___| Y \ ___/ \___ \ \___ \\ \___( <_> ) | \ | | / /_/ > +# \______ /___| /\___ >____ >____ >\______ /\____/|___| /__| |__\___ / +# \/ \/ \/ \/ \/ \/ \/ /_____/ +''' +cool ascii > http://patorjk.com/software/taag +chess-ICON > https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode +more cool unicode ICON > https://www.unicode.org/charts/ +color codes cheatsheet > https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f113fd25b''' + +import typing + +# ------------ BOARD ----------------- +''' +black > '\x1b[30m' +red > '\x1b[31m' +green > '\x1b[32m' +yellow > '\x1b[33m' +blue > '\x1b[34m' +magenta > '\x1b[35m' +cyan > '\x1b[36m' +white > '\x1b[37m' ''' + +WHITECOLOR: typing.Final[str] = '\x1b[36m' +BLACKCOLOR: typing.Final[str] = '\x1b[31m' +SPACECOLOR: typing.Final[str] = '' + +WHITE_KING_ICON: typing.Final[str] = '\u265A' +WHITE_QUEEN_ICON: typing.Final[str] = '\u265B' +WHITE_ROOK_ICON: typing.Final[str] = '\u265C' +WHITE_BISHOP_ICON: typing.Final[str] = '\u265D' +WHITE_KNIGHT_ICON: typing.Final[str] = '\u265E' +WHITE_PAWN_ICON: typing.Final[str] = '\u265F' + +SPACE_ICON: str = ' ' + +BLACK_KING_ICON: str = '\u265A' +BLACK_QUEEN_ICON: str = '\u265B' +BLACK_ROOK_ICON: str = '\u265C' +BLACK_BISHOP_ICON: str = '\u265D' +BLACK_KNIGHT_ICON: str = '\u265E' +BLACK_PAWN_ICON: str = '\u265F' + +STOCKFISH_PATH: str = '/opt/homebrew/bin/stockfish' # path to installed stockfish bin +stockfish_depth: int = 10 # default calculation depth for stockfish engine +minimax_depth: int = 4 # default calculation depth for minimax algorithm + +# ------------ PARSING -------------- + +PIECE_MAP: typing.Final[dict[str, str]] = { # add other languages ('Springer': 'N') + 'rook': 'R', 'Rook': 'R', 'ROOK': 'R', 'Turm': 'R', 'T': 'R', + 'knight': 'N', 'Knight': 'N', 'KNIGHT': 'N', 'Springer': 'N', 'S': 'N', + 'bishop': 'B', 'Bishop': 'B', 'BISHOP': 'B', 'L': 'B', 'Läufer': 'B', + 'queen': 'Q', 'Queen': 'Q', 'QUEEN': 'Q', 'Dame': 'Q', 'D': 'Q', + 'king': 'K', 'King': 'K', 'KING': 'K', + 'pawn': 'P', 'Pawn': 'P', 'PAWN': 'P'} + +# value = True if capture else False +ACTION_MAP: typing.Final[dict[str, bool]] = {' captures ': True, ' takes ': True, ' goes to ': False, ' goes ': False, ' to ': False, ' x ': True, ' - ': False, ' / ': False, 'x': True, '-': False, '/': False, '_': False, ' ': False} # put longer strings to the front so they match before ' ' does! + +PROMOTION_MAP: typing.Final[dict[str, str]] = { + ' queen': 'Q', ' = q': 'Q', ' =q': 'Q', ' /q': 'Q', '=q': 'Q', '/q': 'Q', ' q': 'Q', 'q': 'Q', ' QUEEN': 'Q', ' Queen': 'Q', ' = Q': 'Q', ' =Q': 'Q', ' /Q': 'Q', '=Q': 'Q', '/Q': 'Q', ' Q': 'Q', 'Q': 'Q', + ' rook': 'R', ' = r': 'R', ' =r': 'R', ' /r': 'R', '=r': 'R', '/r': 'R', ' r': 'R', 'r': 'R', ' ROOK': 'R', ' Rook': 'R', ' = R': 'R', ' =R': 'R', ' /R': 'R', '=R': 'R', '/R': 'R', ' R': 'R', 'R': 'R', + ' knight': 'N', ' = n': 'N', ' =n': 'N', ' /n': 'N', '=n': 'N', '/n': 'N', ' n': 'N', 'n': 'N', ' KNIGHT': 'N', ' Knight': 'N', ' = N': 'N', ' =N': 'N', ' /N': 'N', '=N': 'N', '/N': 'N', ' N': 'N', 'N': 'N', + ' bishop': 'B', ' = b': 'B', ' =b': 'B', ' /b': 'B', '=b': 'B', '/b': 'B', ' b': 'B', 'b': 'B', ' BISHOP': 'B', ' Bishop': 'B', ' = B': 'B', ' =B': 'B', ' /B': 'B', '=B': 'B', '/B': 'B', ' B': 'B', 'B': 'B'} + +# value = True if short castling else False +CASTLING_MAP: typing.Final[dict[str, bool]] = { + 'short castling': True, 'castle short': True, 'kingside castling': True, 'castle kingside': True, 'O-O': True, '0-0': True, '00': True, 'o-o': True, 'oo': True, 'OO': True, + 'long castling': False, 'castle long': False, 'queenside castling': False, 'castle queenside': False, 'O-O-O': False, '0-0-0': False, '000': False, 'o-o-o': False, 'ooo': False, 'OOO': False} + +# value = True if check else False (checkmate) +CHECK_OR_CHECKMATE_MAP: typing.Final[dict[str, str]] = { + ' with check': '+', ' CHECK': '+', ' check': '+', ' +': '+', '+': '+', + ' with checkmate': '#', ' CHECKMATE': '#', ' checkmate': '#', ' ++': '#', ' #': '#', '++': '#', '#': '#'} + +# ------------ EVAL FUNCTION -------------- + +PIECEVALUE: typing.Final[dict[str, int]] = {'K': 20_000, 'Q': 900, 'R': 500, 'B': 330, 'N': 320, 'P': 100,'k': -20_000, 'q': -900, 'r': -500, 'b': -330, 'n': -320, 'p': -100, '.': 0} + +postables_struct = dict[str, tuple[ + tuple[int, int, int, int, int, int, int, int], + tuple[int, int, int, int, int, int, int, int], + tuple[int, int, int, int, int, int, int, int], + tuple[int, int, int, int, int, int, int, int], + tuple[int, int, int, int, int, int, int, int], + tuple[int, int, int, int, int, int, int, int], + tuple[int, int, int, int, int, int, int, int], + tuple[int, int, int, int, int, int, int, int]]] + +POSTABLES: typing.Final[postables_struct] = { + + 'R': ((0, 0, 0, 0, 0, 0, 0, 0), + (5, 10, 10, 10, 10, 10, 10, 5), + (-5, 0, 0, 0, 0, 0, 0, -5), + (-5, 0, 0, 0, 0, 0, 0, -5), + (-5, 0, 0, 0, 0, 0, 0, -5), + (-5, 0, 0, 0, 0, 0, 0, -5), + (-5, 0, 0, 0, 0, 0, 0, -5), + (0, 0, 0, 5, 5, 0, 0, 0)), + + 'N': ((-50, -40, -30, -30, -30, -30, -40, -50), + (-40, -20, 0, 0, 0, 0, -20, -40), + (-30, 0, 10, 15, 15, 10, 0, -30), + (-30, 5, 15, 20, 20, 15, 5, -30), + (-30, 0, 15, 20, 20, 15, 0, -30), + (-30, 5, 10, 15, 15, 10, 5, -30), + (-40, -20, 0, 5, 5, 0, -20, -40), + (-50, -40, -30, -30, -30, -30, -40, -50)), + + 'B': ((-20, -10, -10, -10, -10, -10, -10, -20), + (-10, 0, 0, 0, 0, 0, 0, -10), + (-10, 0, 5, 10, 10, 5, 0, -10), + (-10, 5, 5, 10, 10, 5, 5, -10), + (-10, 0, 10, 10, 10, 10, 0, -10), + (-10, 10, 10, 10, 10, 10, 10, -10), + (-10, 5, 0, 0, 0, 0, 5, -10), + (-20, -10, -10, -10, -10, -10, -10, -20)), + + 'Q': ((-20, -10, -10, -5, -5, -10, -10, -20), + (-10, 0, 0, 0, 0, 0, 0, -10), + (-10, 0, 5, 5, 5, 5, 0, -10), + (-5, 0, 5, 5, 5, 5, 0, -5), + (0, 0, 5, 5, 5, 5, 0, -5), + (-10, 5, 5, 5, 5, 5, 0, -10), + (-10, 0, 5, 0, 0, 0, 0, -10), + (-20, -10, -10, -5, -5, -10, -10, -20)), + + 'P': ((0, 0, 0, 0, 0, 0, 0, 0), + (50, 50, 50, 50, 50, 50, 50, 50), + (10, 10, 20, 30, 30, 20, 10, 10), + (5, 5, 10, 25, 25, 10, 5, 5), + (0, 0, 0, 20, 20, 0, 0, 0), + (5, -5, -10, 0, 0, -10, -5, 5), + (5, 10, 10, -20, -20, 10, 10, 5), + (0, 0, 0, 0, 0, 0, 0, 0)), + + 'p': ((0, 0, 0, 0, 0, 0, 0, 0), + (-5, -10, -10, 20, 20, -10, -10, -5), + (-5, 5, 10, 0, 0, 10, 5, -5), + (0, 0, 0, -20, -20, 0, 0, 0), + (-5, -5, -10, -25, -25, -10, -5, -5), + (-10, -10, -20, -30, -30, -20, -10, -10), + (-50, -50, -50, -50, -50, -50, -50, -50), + (0, 0, 0, 0, 0, 0, 0, 0)), + + 'K_end': ((-50, -40, -30, -20, -20, -30, -40, -50), # end game + (-30, -20, -10, 0, 0, -10, -20, -30), + (-30, -10, 20, 30, 30, 20, -10, -30), + (-30, -10, 30, 40, 40, 30, -10, -30), + (-30, -10, 30, 40, 40, 30, -10, -30), + (-30, -10, 20, 30, 30, 20, -10, -30), + (-30, -30, 0, 0, 0, 0, -30, -30), + (-50, -30, -30, -30, -30, -30, -30, -50)), + + 'K_middle': ((-30, -40, -40, -50, -50, -40, -40, -30), # middle game + (-30, -40, -40, -50, -50, -40, -40, -30), + (-30, -40, -40, -50, -50, -40, -40, -30), + (-30, -40, -40, -50, -50, -40, -40, -30), + (-20, -30, -30, -40, -40, -30, -30, -20), + (-10, -20, -20, -20, -20, -20, -20, -10), + (20, 20, 0, 0, 0, 0, 20, 20), + (20, 30, 10, 0, 0, 10, 30, 20), + ), + 'r': ((0, 0, 0, -5, -5, 0, 0, 0), + (5, 0, 0, 0, 0, 0, 0, 5), + (5, 0, 0, 0, 0, 0, 0, 5), + (5, 0, 0, 0, 0, 0, 0, 5), + (5, 0, 0, 0, 0, 0, 0, 5), + (5, 0, 0, 0, 0, 0, 0, 5), + (-5, -10, -10, -10, -10, -10, -10, -5), + (0, 0, 0, 0, 0, 0, 0, 0)), + + 'n': ((50, 40, 30, 30, 30, 30, 40, 50), + (40, 20, 0, -5, -5, 0, 20, 10), + (30, -5, -10, -15, -15, -10, -5, 30), + (30, 0, -15, -20, -20, -15, 0, 30), + (30, -5, -15, -20, -20, -15, -5, 30), + (30, 0, -10, -15, -15, -10, 0, 30), + (40, 20, 0, 0, 0, 0, 20, 40), + (50, 40, 30, 30, 30, 30, 40, 50)), + + 'b': ((20, 10, 10, 10, 10, 10, 10, 20), + (10, -5, 0, 0, 0, 0, 0, 0, -5, 10), + (10, -10, -10, -10, -10, -10, -10, 10), + (10, 0, -10, -10, -10, -10, 0, 10), + (10, -5, -5, -5, -5, -5, -5, 10), + (10, 0, -5, -10, -10, -5, 0, 10), + (10, 0, 0, 0, 0, 0, 0, 10), + (20, 10, 10, 10, 10, 10, 10, 20)), + + 'k_end': ((50, 30, 30, 30, 30, 30, 30, 50), # end game + (30, 30, 0, 0, 0, 0, 30, 30), + (30, 10, -20, -30, -30, -20, 10, 30), + (30, 10, -30, -40, -40, -30, 10, 30), + (30, 10, -30, -40, -40, -30, 10, 30), + (30, 10, -20, -30, -30, -20, 10, 30), + (30, 20, 10, 0, 0, 10, 20, 30), + (50, 40, 30, 20, 20, 30, 40, 50)), + + 'k_middle': ((-20, -30, -10, 0, 0, -10, -30, -20), # middle game + (-20, -20, 0, 0, 0, 0, -20, -20), + (10, 20, 20, 20, 20, 20, 20, 10), + (20, 30, 30, 40, 40, 30, 30, 20), + (30, 40, 40, 50, 50, 40, 40, 30), + (30, 40, 40, 50, 50, 40, 40, 30), + (30, 40, 40, 50, 50, 40, 40, 30), + (30, 40, 40, 50, 50, 40, 40, 30)), + + 'q': ((20, 10, 10, -5, -5, 10, 10, 20), + (10, 0, -5, 0, 0, 0, 0, 10), + (10, -5, -5, -5, -5, -5, 0, 10), + (0, 0, -5, -5, -5, -5, 0, 5), + (5, 0, -5, -5, -5, -5, 0, 5), + (10, 0, -5, -5, -5, -5, 0, 10), + (10, 0, 0, 0, 0, 0, 0, 10), + (20, 10, 10, 5, 5, 10, 10, 20)) + } \ No newline at end of file -- cgit v1.2.3