added Figures
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from cmd import PROMPT
|
||||||
import os
|
import os
|
||||||
# region Constants
|
# region Constants
|
||||||
# White Constants
|
# White Constants
|
||||||
@@ -10,7 +11,18 @@ WHITE, BLACK = 0, 1
|
|||||||
KIN, QUE, BIS, NHT, ROO, PAW = range(6)
|
KIN, QUE, BIS, NHT, ROO, PAW = range(6)
|
||||||
NO_PIECE = 15
|
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
|
# Square Constants
|
||||||
A8, B8, C8, D8, E8, F8, G8, H8 = range(56, 64)
|
A8, B8, C8, D8, E8, F8, G8, H8 = range(56, 64)
|
||||||
@@ -74,12 +86,6 @@ RAYS_W = [0] * 64
|
|||||||
RAYS_NW = [0] * 64
|
RAYS_NW = [0] * 64
|
||||||
|
|
||||||
clear = lambda: os.system('clear')
|
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
|
# endregion
|
||||||
|
|
||||||
@@ -428,23 +434,29 @@ class Bitboard():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def print_board(self):
|
def print_board(self):
|
||||||
board = ["--"] * 64
|
board = [" "] * 64
|
||||||
if self.move_list:
|
if self.move_list:
|
||||||
move = self.move_list[-1]
|
move = self.move_list[-1]
|
||||||
last_sq = (move >> 6) & 0x3F
|
last_sq = (move >> 6) & 0x3F
|
||||||
board[last_sq] = " "
|
board[last_sq] = f"{COL.BG_MOVE} "
|
||||||
for pce in range(12):
|
for pce in range(12):
|
||||||
locations = self.bitboards[pce]
|
locations = self.bitboards[pce]
|
||||||
while locations:
|
while locations:
|
||||||
index = (locations & -locations).bit_length() - 1
|
index = (locations & -locations).bit_length() - 1
|
||||||
board[index] = PIECE_TO_STR[pce]
|
board[index] = PIECE_TO_SYM[pce]
|
||||||
locations &= (locations - 1)
|
locations &= (locations - 1)
|
||||||
|
|
||||||
for c in range(7, -1, -1):
|
for c in range(7, -1, -1):
|
||||||
print(f"{c+1} ", end="")
|
print(f"{c+1} ", end="")
|
||||||
for r in range(8):
|
for r in range(8):
|
||||||
print(board[r + (c * 8)], end=" ")
|
|
||||||
print("")
|
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")
|
print(" A B C D E F G H\n")
|
||||||
|
|
||||||
def initialize():
|
def initialize():
|
||||||
@@ -522,17 +534,17 @@ def initialize():
|
|||||||
RAYS_SW[sq] |= (1 << (i * 8 + j))
|
RAYS_SW[sq] |= (1 << (i * 8 + j))
|
||||||
i -= 1; j -= 1
|
i -= 1; j -= 1
|
||||||
|
|
||||||
|
|
||||||
initialize()
|
initialize()
|
||||||
board = Bitboard()
|
board = Bitboard()
|
||||||
turn = -1
|
turn = 0
|
||||||
text = "Please input move: "
|
text = f"Please input move: "
|
||||||
while board.playing:
|
while board.playing:
|
||||||
clear()
|
clear()
|
||||||
print(f"\n -------- CHESS -------- Turn: {turn}")
|
print(f"{COL.RESET}\n ---- CHESS ---- Turn: {turn}")
|
||||||
board.print_board()
|
board.print_board()
|
||||||
print(text, end="")
|
move = input(text)
|
||||||
move = input()
|
if len(move) !=5 or not board.encode_and_make_move(move):
|
||||||
if not board.encode_and_make_move(move):
|
|
||||||
text = "Move not possible new move: "
|
text = "Move not possible new move: "
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user