13 for (
int piece =
wP; piece <=
bK; ++piece) {
19 for (
int piece =
wP; piece <=
bK; ++piece) {
20 for (
int count = 0; count < pos->
pceNum[piece]; ++count) {
21 const int square = pos->
pList[piece][count];
29 int tempPceNum[13] = {0};
30 int tempBigPce[2] = {0};
31 int tempMajPce[2] = {0};
32 int tempMinPce[2] = {0};
33 int tempMaterial[2] = {0};
35 U64 tempPawns[3] = {0ULL, 0ULL, 0ULL};
41 for (
int piece =
wP; piece <=
bK; ++piece) {
42 for (
int idx = 0; idx < pos->
pceNum[piece]; ++idx) {
43 const int sq120 = pos->
pList[piece][idx];
49 for (
int sq64 = 0; sq64 < 64; ++sq64) {
50 const int sq120 =
SQ120(sq64);
51 const int piece = pos->
pieces[sq120];
62 for (
int piece =
wP; piece <=
bK; ++piece) {
67 int popCount =
CNT(tempPawns[
WHITE]);
71 popCount =
CNT(tempPawns[
BOTH]);
75 while (tempPawns[
WHITE]) {
76 const int sq64 =
POP(&tempPawns[
WHITE]);
80 while (tempPawns[
BLACK]) {
81 const int sq64 =
POP(&tempPawns[
BLACK]);
85 while (tempPawns[
BOTH]) {
86 const int sq64 =
POP(&tempPawns[
BOTH]);
113 for (
int index = 0; index <
BRD_SQ_NUM; ++index) {
114 const int square = index;
115 const int piece = pos->
pieces[index];
138 }
else if (piece ==
bP) {
157 while ((rank >=
RANK_1) && *fen) {
160 case 'p': piece =
bP;
break;
161 case 'r': piece =
bR;
break;
162 case 'n': piece =
bN;
break;
163 case 'b': piece =
bB;
break;
164 case 'k': piece =
bK;
break;
165 case 'q': piece =
bQ;
break;
166 case 'P': piece =
wP;
break;
167 case 'R': piece =
wR;
break;
168 case 'N': piece =
wN;
break;
169 case 'B': piece =
wB;
break;
170 case 'K': piece =
wK;
break;
171 case 'Q': piece =
wQ;
break;
173 case '1':
case '2':
case '3':
case '4':
174 case '5':
case '6':
case '7':
case '8':
176 runCount = *fen -
'0';
187 printf(
"FEN error \n");
191 for (
int i = 0; i < runCount; ++i) {
192 const int sq64 = rank * 8 + file;
193 const int sq120 =
SQ120(sq64);
194 if (piece !=
EMPTY) {
195 pos->
pieces[sq120] = piece;
202 ASSERT(*fen ==
'w' || *fen ==
'b');
206 for (
int i = 0; i < 4; ++i) {
207 if (*fen ==
' ')
break;
222 const int fileIdx = fen[0] -
'a';
223 const int rankIdx = fen[1] -
'1';
237 for (
int index = 0; index <
BRD_SQ_NUM; ++index) {
240 for (
int sq64 = 0; sq64 < 64; ++sq64) {
244 for (
int side = 0; side < 2; ++side) {
251 for (
int p = 0; p < 3; ++p) {
252 pos->
pawns[p] = 0ULL;
255 for (
int piece = 0; piece < 13; ++piece) {
273 printf(
"\nGame Board:\n\n");
276 printf(
"%d ", rank + 1);
278 const int square =
FR2SQ(file, rank);
279 const int piece = pos->
pieces[square];
287 printf(
"%3c",
'a' + file);
292 printf(
"enPas:%d\n", pos->
enPas);
293 printf(
"castle:%c%c%c%c\n",
298 printf(
"PosKey:%llX\n", pos->
posKey);
302 int tempPiecesArray[64];
303 int mirroredSide = pos->
side ^ 1;
304 static const int swapPiece[13] = {
EMPTY,
bP,
bN,
bB,
bR,
bQ,
bK,
wP,
wN,
wB,
wR,
wQ,
wK };
305 int mirroredCastlePerm = 0;
306 int mirroredEnPas =
NO_SQ;
317 for (
int sq = 0; sq < 64; ++sq) {
323 for (
int sq = 0; sq < 64; ++sq) {
324 const int mapped = swapPiece[tempPiecesArray[sq]];
328 pos->
side = mirroredSide;
330 pos->
enPas = mirroredEnPas;
bool isBoardStateValid(const S_BOARD *pos)
Performs a full internal consistency check of the board state.
void resetBoardState(S_BOARD *pos)
Reset board to empty state.
void mirrorBoardPosition(S_BOARD *pos)
Flip the board vertically, swapping colors and positions.
int loadFEN(char *fen, S_BOARD *pos)
Parse a FEN string into the given board state.
void updateListsMaterial(S_BOARD *pos)
Update piece lists, material counts, and pawn bitboards from scratch.
bool isPieceListValid(const S_BOARD *pos)
Validate that piece list array is consistent with board state.
void printBoardState(const S_BOARD *pos)
Print the board to stdout in a human-readable format.
int pieceColor[13]
Color of each piece type.
bool isBigPiece[13]
Lookup tables for piece attributes.
char pieceToCharacter[]
Maps piece, side-to-move, rank and file to their character symbol.
int pieceValue[13]
Material value of each piece type.
int Mirror64[64]
Square mirroring lookup from white's perspective.
U64 generatePositionKeys(const S_BOARD *board)
Generates a Zobrist hash key for the given board position.
int rankIndex120[BRD_SQ_NUM]
int PceValidEmptyOffbrd(const int pce)
Checks if the given piece code is empty, valid, or OFFBOARD.
int SqOnBoard(const int sq)
Checks if a given square index refers to a valid on-board square.
int SideValid(const int side)
Checks if the given side identifier is valid.