Chess-Update

This commit is contained in:
VS-Code
2026-02-09 16:21:00 +01:00
parent cb2e2ba210
commit f1d1f436af

View File

@@ -16,8 +16,10 @@ A3, B3, C3, D3, E3, F3, G3, H3 = range(16, 24)
A2, B2, C2, D2, E2, F2, G2, H2 = range(8, 16)
A1, B1, C1, D1, E1, F1, G1, H1 = range(8)
NOT_A_FILE = 0xfefefefefefefefe
NOT_H_FILE = 0x7f7f7f7f7f7f7f7f
NOT_A = 0xfefefefefefefefe
NOT_H = 0x7f7f7f7f7f7f7f7f
NOT_AB = 0xfcfcfcfcfcfcfcfc
NOT_GH = 0x3f3f3f3f3f3f3f3f
FULL_MASK = 0xffffffffffffffff
INDEX_TO_FIELD = [
@@ -31,25 +33,12 @@ INDEX_TO_FIELD = [
"a8", "b8", "c8", "d8", "e8", "f8", "g8", "h8",
]
''' Board Index:
a b c d e f g h
8 [56] [57] [58] [59] [60] [61] [62] [63]
7 [48] [49] [50] [51] [52] [53] [54] [55]
6 [40] [41] [42] [43] [44] [45] [46] [47]
5 [32] [33] [34] [35] [36] [37] [38] [39]
4 [24] [25] [26] [27] [28] [29] [30] [31]
3 [16] [17] [18] [19] [20] [21] [22] [23]
2 [08] [09] [10] [11] [12] [13] [14] [15]
1 [00] [01] [02] [03] [03] [05] [06] [07]
'''
class bitboard():
class Bitboard():
def __init__(self) -> None:
# WHITE 0:King, 1:Queen, 2:Bishop, 3:Knight, 4:Rook, 5:Pawn
# BLACK 6:King, 7:Queen, 8:Bishop, 9:Knight, 10:Rook, 11:Pawn
self.bitboards = [0, 0, 0, 0, 0, 0, # List of All Bitboards
self.bitboards = [0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0]
self.side_to_move = WHITE
@@ -82,7 +71,8 @@ class bitboard():
# King Moves
king = self.bitboards[KIN]
king_moves = 0
king_moves |= king
king_moves = (king & NOT_A) >> 1 | (king & NOT_A) << 7 | king << 8 | (king & NOT_H) << 9 | (king & NOT_H) << 1 | (king & NOT_H) >> 7 | king >> 8 | (king & NOT_A) >> 9
king_moves &= FULL_MASK
pass
@@ -90,8 +80,7 @@ class bitboard():
def make_move(self, move):
# MOVE:
# Aufbau:
# Setup
# Bit 0-5: Target (6 Bit, Index: 0-63)
# Bit 6-11: Source (6 Bit, Index: 0-63)
# Bit 12-15: Flags (4 Bit)
@@ -102,12 +91,59 @@ class bitboard():
pass
def encode_move():
pass
def decode_move():
pass
KIN_ATTACKS = [0] * 64
NHT_ATTACKS = [0] * 64
PAW_ATTACKS = [0] * 128 # 0-63 für Weiße Bauern, 64-127 für Schwarze Bauern
RAY_N = [0] * 64
RAY_NE = [0] * 64
RAY_E = [0] * 64
RAY_SE = [0] * 64
RAY_S = [0] * 64
RAY_SW = [0] * 64
RAY_W = [0] * 64
RAY_NW = [0] * 64
def initialize():
for sq in range(64):
# King
kin = 1 << sq
kin_attacks = (kin & NOT_A) << 7 | kin << 8 | (kin & NOT_H) << 9 | (kin & NOT_H) << 1 | \
(kin & NOT_H) >> 7 | kin >> 8 | (kin & NOT_A) >> 9 | (kin & NOT_A) >> 1
KIN_ATTACKS[sq] = kin_attacks & FULL_MASK
# Knight
nht = 1 << sq
nht_attacks = (nht & NOT_AB) << 6 | (nht & NOT_A) << 15 | (nht & NOT_H) << 17 | (nht & NOT_GH) << 10 | \
(nht & NOT_GH) >> 6 | (nht & NOT_H) >> 15 | (nht & NOT_A) >> 17 | (nht & NOT_AB) >> 10
NHT_ATTACKS[sq] = nht_attacks & FULL_MASK
# Pawns
paw = 1 << sq
w_attacks = (paw & NOT_A) << 7 | (paw & NOT_H) << 9
PAW_ATTACKS[sq] = w_attacks & FULL_MASK
b_attacks = (paw & NOT_A) >> 9 | (paw & NOT_H) >> 7
PAW_ATTACKS[sq + 64] = b_attacks & FULL_MASK
# Rays
# North
''' Board Index:
a b c d e f g h
8 [56] [57] [58] [59] [60] [61] [62] [63]
7 [48] [49] [50] [51] [52] [53] [54] [55]
6 [40] [41] [42] [43] [44] [45] [46] [47]
5 [32] [33] [34] [35] [36] [37] [38] [39]
4 [24] [25] [26] [27] [28] [29] [30] [31]
3 [16] [17] [18] [19] [20] [21] [22] [23]
2 [08] [09] [10] [11] [12] [13] [14] [15]
1 [00] [01] [02] [03] [03] [05] [06] [07]
'''