make build
This engine can be tested with Xboard.
src:- Bot.cpp -> Gets done the two main functionalities:
recording a move(received from opponent as well as the one sended by the engine), andcalculates the next movebased on all possible moves. - Main.cpp -> Handles the
communicationwith thexboard - PieceHandlers.cpp -> Calculates
every field that a piece has, creates pieces and calculatesits possible moves, which in turn will be added to the poll of all possible moves. - Table.cpp -> Initializes the
2D array(the chess board) with the pieces intheir proper positionat the start of a game and most notably goes through all the squares andcalculates its fields(who isattacked byand many more). - Move.cpp -> Creates and handles Move objects, converts the
string representationof a move to aindexin the table and opposite, checks what kind of a move is (drop in, normal, promotion based on which parameters are set: dst, src, replacement) - Test.cpp -> File used by us for
debuggingpurposeses
- Bot.cpp -> Gets done the two main functionalities:
include-> header filesbuild-> objects created in the process of compiling
- For
memory saving purposes, we chose to save the square of a chess table and its parameteres as aone byte, in which every bit represents something as follows:- bit 7: the
colourof the piece(black/white) - bit [6:4]: encoding of the type of piece (Pawn, Rook, Bishop, Knight, King, Queen) (check
Piece.h) - bit 3: if the square is
attackedby ablackpiece - bit 2: if the square is
attackedby awhitepiece - bit 1: if the piece in the square is an
attackerof theopponent's king - bit 0: if the piece in the square is a
protectorof its king
- bit 7: the
rocinfo-> which tells us wheter the castling is available: first 4 bits for whites: 1st empty, 2nd theleft rook moved, 3rdking moved, 4thright rook moved, and exactly the same for the rest of 4 bits for black.wKx, wKy, bKx, bKy-> thecoordonatesof thewhite & black kingon the table, for easier finding whether the king is incheck.capturedByWhite/capturedByBlack-> two vectors of pieces captured by either side that are available for dropping in.last_move-> a Move object representing the last move theopponent of sideToMoveplayer did.promotedPawnsWhite/promotedPawnsBlack-> vector that contains the position of thepromotedpawns of either side, so whencapturingit by the opposite player, he will get apawn.table[8][8]-> the chess table itself, every element being an 1 byte described above.
- Checks if it's a
promotion(in this case, itscoordinatesshould be retained inpromotedPawns*to keep monitoring them) - Checks if it's an
en passantmove (the piece that was captured by passing is added tocaptured*and later the piece itself that moved in diagonal is recorded) - Checks if its a castling (king moves
2 squares-> therookthat he chooses ismoved to the specific spot, and later the king is moved as well;cancelsallcastlingfor the player) - Checks if its a
rook/king that moved-> mark them inrocinfofor knowing in the future if the castling will be available. - After all the
checks were done, proceed with the recording- the move has a
source-> the piece is saved, the square is marked asNAP(not a piece) - the move has a
destination-> the piece that wassavedisputthere, and if there was a piece, means its acaptureso its save in captured pieces - the move has a
replacement-> puts the piece to the destination
- the move has a
updates the statesfor all the squares of the table ->recomputethe rest of the bits of atable square(attacked by who, attacker of the king, protector of the king).
- Going through all the squares of the table, checks what kind of piece there is:
NAP-> do nothing about itPAWN/KNIGHT/KING-> they can attack as much as they can move(pawnonesquare infrontto theleft/rightand knight inL shape)BISHOP/QUEEN/ROOK-> they canattack the empty slotsin all directions they can moveuntillapiece is there, and that would be thelast squaretheycan attackin thatdirection. If apieceis in therange of attackof one of these 3 pieces, checks if the range would countinue on empty squareswithout it, if it would find akingof the opposite colour, in this case, the piece in between is aprotector of the kingand should be marked respectively.
generateAllPossibleMoves(Table.h): firstly, it checks if the king is in check, in this situation only a specific moves can be made:constraints-> where the destination of the moves available should be(to block the attackers check or to capture it)- finds the attacker's position, and thus what kind of piece that is too, and adds the empty spots in the range to the king as
constraints
- next, based on
if there is any constraintgenerated above, the moves available for each piece is avalid oneif itblocks the attacker's(if any)check/ moves to an empty square or captures an enemy piece; the moves available for thekingthat is in check are different, he has aking)constraints, the range of the attacker, where he can not move to. - lastly, adds to the
list of movesthedrop inpossible move:for each empty spoton the table, adds a possible move as dropping ina piece from the captured ones(except firstandlast rowforpawndrop in)
- For the purpose of
testing the castling, if thereisacastlemove, itwill choosethe first one available,otherwise, it will generate arandomindex from the poll of available moves and send that one.