From bbe3a648fb0447e4639930fe45b779d7cb5e0886 Mon Sep 17 00:00:00 2001 From: VS-Code <-> Date: Sat, 14 Feb 2026 15:29:12 +0100 Subject: [PATCH] added Figures --- chess/chess_64.py | 50 +++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/chess/chess_64.py b/chess/chess_64.py index b82b4d7..38b8d38 100644 --- a/chess/chess_64.py +++ b/chess/chess_64.py @@ -1,3 +1,4 @@ +from cmd import PROMPT import os # region Constants # White Constants @@ -10,7 +11,18 @@ WHITE, BLACK = 0, 1 KIN, QUE, BIS, NHT, ROO, PAW = range(6) NO_PIECE = 15 -PIECE_TO_STR = ["wK", "wQ", "wB", "wN", "wR", "wP", "bK", "bQ", "bB", "bN", "bR", "bP"] +class COL(): + FG_WHITE = "\033[38;5;253m" + FG_BLACK = "\033[38;5;232m" + BG_WHITE = "\033[48;5;230m" + BG_DARK = "\033[48;5;71m" + BG_MOVE = "\033[48;5;249m" + RESET = "\033[0m" + +PIECE_TO_STR = ["wK", "wQ", "wB", "wN", "wR", "wP", + "bK", "bQ", "bB", "bN", "bR", "bP"] +PIECE_TO_SYM = ["♔", "♕", "♗", "♘", "♖", "♙", + "♚", "♛", "♝", "♞", "♜", "♟"] # Square Constants A8, B8, C8, D8, E8, F8, G8, H8 = range(56, 64) @@ -74,12 +86,6 @@ RAYS_W = [0] * 64 RAYS_NW = [0] * 64 clear = lambda: os.system('clear') -class COL(): - def __init__(self) -> None: - self.W = "\033[97m" - self.B = "\033[30m" - self.BG_W = "\033[47m" - self.BW_B = "\033[40m" # endregion @@ -428,24 +434,30 @@ class Bitboard(): return False def print_board(self): - board = ["--"] * 64 + board = [" "] * 64 if self.move_list: move = self.move_list[-1] last_sq = (move >> 6) & 0x3F - board[last_sq] = " " + board[last_sq] = f"{COL.BG_MOVE} " for pce in range(12): locations = self.bitboards[pce] while locations: index = (locations & -locations).bit_length() - 1 - board[index] = PIECE_TO_STR[pce] + board[index] = PIECE_TO_SYM[pce] locations &= (locations - 1) for c in range(7, -1, -1): print(f"{c+1} ", end="") for r in range(8): - print(board[r + (c * 8)], end=" ") - print("") - print(" A B C D E F G H \n") + + bg_col = COL.BG_WHITE if (r + c) % 2 != 0 else COL.BG_DARK + #fg_col = COL.FG_WHITE if (board[r + (c * 8)][0]) != "b" else COL.FG_BLACK + + print(f"{bg_col}{COL.FG_BLACK}{board[r + (c * 8)]}", end=" ") + + + print(COL.RESET) + print(" A B C D E F G H\n") def initialize(): ''' @@ -522,17 +534,17 @@ def initialize(): RAYS_SW[sq] |= (1 << (i * 8 + j)) i -= 1; j -= 1 + initialize() board = Bitboard() -turn = -1 -text = "Please input move: " +turn = 0 +text = f"Please input move: " while board.playing: clear() - print(f"\n -------- CHESS -------- Turn: {turn}") + print(f"{COL.RESET}\n ---- CHESS ---- Turn: {turn}") board.print_board() - print(text, end="") - move = input() - if not board.encode_and_make_move(move): + move = input(text) + if len(move) !=5 or not board.encode_and_make_move(move): text = "Move not possible new move: " continue