I see that I added board.h that I did not need to do at step 19 to data.cpp because data.cpp include extglobals.h that include board.h so I delete it.
I want to add
for (int i = 0; i < 64; i++) square = EMPTY; to the init function in board.cpp but EMPTY is not defined
so I need to add it to extglobals.h and also to define the value of EMPTY to be 0 in globals.h
#pragma once
#include "defines.h"//needed to include it so the compiler can know that MAX_CMD_BUFF is the constant I defined there
#include "board.h"
char CMD_BUFF[MAX_CMD_BUFF];
int CMD_BUFF_COUNT = 0;
BitMap BITSET[64];//added at step 18
int BOARDINDEX[9][9]; // index 0 is not used, only 1..8. added at step 19
Board board;//added at step 19
extern const unsigned char EMPTY = 0; // 0000 added in step 20
//I added this file at step 19
#include "extglobals.h"//added in step 20
void Board::init()
{
for (int i = 0; i < 64; i++) square[i] = EMPTY;//added in step 20
}
extern const int A8; extern const int B8; extern const int C8; extern const int D8;//added const for the squares at step 21
extern const int E8; extern const int F8; extern const int G8; extern const int H8;
extern const int A7; extern const int B7; extern const int C7; extern const int D7;
extern const int E7; extern const int F7; extern const int G7; extern const int H7;
extern const int A6; extern const int B6; extern const int C6; extern const int D6;
extern const int E6; extern const int F6; extern const int G6; extern const int H6;
extern const int A5; extern const int B5; extern const int C5; extern const int D5;
extern const int E5; extern const int F5; extern const int G5; extern const int H5;
extern const int A4; extern const int B4; extern const int C4; extern const int D4;
extern const int E4; extern const int F4; extern const int G4; extern const int H4;
extern const int A3; extern const int B3; extern const int C3; extern const int D3;
extern const int E3; extern const int F3; extern const int G3; extern const int H3;
extern const int A2; extern const int B2; extern const int C2; extern const int D2;
extern const int E2; extern const int F2; extern const int G2; extern const int H2;
extern const int A1; extern const int B1; extern const int C1; extern const int D1;
extern const int E1; extern const int F1; extern const int G1; extern const int H1;
In this step I do the following:
1)to define the structure of the function in protos.h
2)to define the function in data.cpp
3)to call the function and use it in command.cpp
void info()//added this function at step 23
{
//target is to display variables for testing
printf("info start\n");
printf("size of board in bytes = %d\n", sizeof(board));
}
void Board::initFromSquares(int input[64], unsigned char next, int fiftyM, int castleW, int castleB, int epSq) //added this function at step 24
{
// sets up the board variables according to the information found in
// the input[64] array
// All board & game initializations are done through this function (including readfen and setup).
//note that I need to add some variables or const in globals.h and extglobals.h in order to use this function
}
//I added this file at step 19
#include "extglobals.h"//added in step 20
void Board::init()
{
for (int i = 0; i < 64; i++) square[i] = EMPTY;//added in step 20
square[E1] = WHITE_KING;//added all the non empty pieces in step 22
square[D1] = WHITE_QUEEN;
square[A1] = WHITE_ROOK;
square[H1] = WHITE_ROOK;
square[B1] = WHITE_KNIGHT;
square[G1] = WHITE_KNIGHT;
square[C1] = WHITE_BISHOP;
square[F1] = WHITE_BISHOP;
square[A2] = WHITE_PAWN;
square[B2] = WHITE_PAWN;
square[C2] = WHITE_PAWN;
square[D2] = WHITE_PAWN;
square[E2] = WHITE_PAWN;
square[F2] = WHITE_PAWN;
square[G2] = WHITE_PAWN;
square[H2] = WHITE_PAWN;
square[E8] = BLACK_KING;
square[D8] = BLACK_QUEEN;
square[A8] = BLACK_ROOK;
square[H8] = BLACK_ROOK;
square[B8] = BLACK_KNIGHT;
square[G8] = BLACK_KNIGHT;
square[C8] = BLACK_BISHOP;
square[F8] = BLACK_BISHOP;
square[A7] = BLACK_PAWN;
square[B7] = BLACK_PAWN;
square[C7] = BLACK_PAWN;
square[D7] = BLACK_PAWN;
square[E7] = BLACK_PAWN;
square[F7] = BLACK_PAWN;
square[G7] = BLACK_PAWN;
square[H7] = BLACK_PAWN;
initFromSquares(square, WHITE_MOVE, 0, CANCASTLEOO + CANCASTLEOOO, CANCASTLEOO + CANCASTLEOOO, 0);//added this at step 25 and
//changed the castle rights to be correct parameters in the opening position in step 26
}
void Board::initFromSquares(int input[64], unsigned char next, int fiftyM, int castleW, int castleB, int epSq) //added this function at step 24
{
// sets up the board variables according to the information found in
// the input[64] array
// All board & game initializations are done through this function (including readfen and setup).
//note that I need to add some variables or const in globals.h and extglobals.h in order to use this function
}
step 27 using all the bitboards that I defined in step 16 in board.h inside board.cpp
I think that step 27 should be closer to step 16 and I will probably rewrite generating a new chess project step after step.
I do not like having variables that I do not use for a long time in the project because it means that I can forget about them so
I think that it is better to use what I define as soon as possible.
In any case this is the code that I added in step 27
void Board::initFromSquares(int input[64], unsigned char next, int fiftyM, int castleW, int castleB, int epSq) //added this function at step 24
{
// sets up the board variables according to the information found in
// the input[64] array
// All board & game initializations are done through this function (including readfen and setup).
//note that I need to add some variables or const in globals.h and extglobals.h in order to use this function
// bitboards
int i;//added step 28
whiteKing = 0;//step 27 initializing all the bitboards that are defined in board.h to be 0.
whiteQueens = 0;
whiteRooks = 0;
whiteBishops = 0;
whiteKnights = 0;
whitePawns = 0;
blackKing = 0;
blackQueens = 0;
blackRooks = 0;
blackBishops = 0;
blackKnights = 0;
blackPawns = 0;
whitePieces = 0;
blackPieces = 0;
occupiedSquares = 0;
// populate the 12 bitboard:/ (step 28)
for (i = 0; i < 64; i++)
{
square[i] = input[i];
if (square[i] == WHITE_KING) whiteKing = whiteKing | BITSET[i];
if (square[i] == WHITE_QUEEN) whiteQueens = whiteQueens | BITSET[i];
if (square[i] == WHITE_ROOK) whiteRooks = whiteRooks | BITSET[i];
if (square[i] == WHITE_BISHOP) whiteBishops = whiteBishops | BITSET[i];
if (square[i] == WHITE_KNIGHT) whiteKnights = whiteKnights | BITSET[i];
if (square[i] == WHITE_PAWN) whitePawns = whitePawns | BITSET[i];
if (square[i] == BLACK_KING) blackKing = blackKing | BITSET[i];
if (square[i] == BLACK_QUEEN) blackQueens = blackQueens | BITSET[i];
if (square[i] == BLACK_ROOK) blackRooks = blackRooks | BITSET[i];
if (square[i] == BLACK_BISHOP) blackBishops = blackBishops | BITSET[i];
if (square[i] == BLACK_KNIGHT) blackKnights = blackKnights | BITSET[i];
if (square[i] == BLACK_PAWN) blackPawns = blackPawns | BITSET[i];
}
whitePieces = whiteKing | whiteQueens | whiteRooks | whiteBishops | whiteKnights | whitePawns;
blackPieces = blackKing | blackQueens | blackRooks | blackBishops | blackKnights | blackPawns;
occupiedSquares = whitePieces | blackPieces;//end of code in step 28
}
step 29
In step 29 I initialize other variables that are about side to move rights to castle for white and black and e.p capture square and fifty move variable
This is the code that I add in step 29 to board.cpp
nextMove = next;//step 29 adding code for initializing some variables that are not 64 bit integer
castleWhite = castleW;
castleBlack = castleB;
epSquare = epSq;
fiftyMove = fiftyM;
Note that part of step 16 should be done later before step 29 and I plan to rewrite it to have a better order of events.