Chess Engine
C++ chess engine with movegen, bitboards, and Arduino-friendly docs
Loading...
Searching...
No Matches
make_move.cpp File Reference
#include "defs.h"
#include <cstdio>
#include "make_move.h"
#include "../util/attack.h"
#include "../util/setup.h"
Include dependency graph for make_move.cpp:

Go to the source code of this file.

Macros

#define HASH_PCE(pce, sq)
#define HASH_CA   (board->posKey ^= (zobristCastleKeys[(board->castlePerm)]))
#define HASH_SIDE   (board->posKey ^= (zobristSideKey))
#define HASH_EP   (board->posKey ^= (zobristPieceKeys[EMPTY][(board->enPas)]))

Functions

static void ClearPiece (const int sq, S_BOARD *board)
static void AddPiece (const int sq, S_BOARD *board, const int piece)
static void MovePiece (const int from, const int to, S_BOARD *board)
int makeMove (S_BOARD *board, int move)
 Make a move; returns non-zero if legal (king not left in check).
void takeMove (S_BOARD *board)
 Undo the last made move.
void makeNullMove (S_BOARD *board)
 Make a null move (side to move toggles, no pieces moved).
void takeNullMove (S_BOARD *board)
 Undo the last null move.

Variables

const int CastlePerm [120]
 Castling permission mask by board square (mailbox 120).

Macro Definition Documentation

◆ HASH_CA

#define HASH_CA   (board->posKey ^= (zobristCastleKeys[(board->castlePerm)]))

Definition at line 10 of file make_move.cpp.

Referenced by makeMove(), and takeMove().

◆ HASH_EP

#define HASH_EP   (board->posKey ^= (zobristPieceKeys[EMPTY][(board->enPas)]))

Definition at line 12 of file make_move.cpp.

Referenced by makeMove(), makeNullMove(), takeMove(), and takeNullMove().

◆ HASH_PCE

#define HASH_PCE ( pce,
sq )
Value:
(board->posKey ^= (zobristPieceKeys[(pce)][(sq)]))
U64 zobristPieceKeys[13][120]
Zobrist hashing keys for each piece on each square.
Definition setup.cpp:22

Definition at line 9 of file make_move.cpp.

Referenced by AddPiece(), ClearPiece(), and MovePiece().

◆ HASH_SIDE

#define HASH_SIDE   (board->posKey ^= (zobristSideKey))

Definition at line 11 of file make_move.cpp.

Referenced by makeMove(), makeNullMove(), takeMove(), and takeNullMove().

Function Documentation

◆ AddPiece()

void AddPiece ( const int sq,
S_BOARD * board,
const int piece )
static

Definition at line 72 of file make_move.cpp.

References ASSERT, S_BOARD::bigPce, BOTH, HASH_PCE, isBigPiece, isMajorPiece, S_BOARD::majPce, S_BOARD::material, S_BOARD::minPce, S_BOARD::pawns, S_BOARD::pceNum, pieceColor, S_BOARD::pieces, pieceValue, pieceValueid(), S_BOARD::pList, SETBIT, SideValid(), SQ64, and SqOnBoard().

Referenced by makeMove(), and takeMove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearPiece()

void ClearPiece ( const int sq,
S_BOARD * board )
static

Definition at line 30 of file make_move.cpp.

References ASSERT, S_BOARD::bigPce, BOTH, CLRBIT, EMPTY, HASH_PCE, isBigPiece, isBoardStateValid(), isMajorPiece, S_BOARD::majPce, S_BOARD::material, S_BOARD::minPce, S_BOARD::pawns, S_BOARD::pceNum, pieceColor, S_BOARD::pieces, pieceValue, pieceValueid(), S_BOARD::pList, SideValid(), SQ64, and SqOnBoard().

Referenced by makeMove(), and takeMove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeMove()

int makeMove ( S_BOARD * board,
int move )

Make a move; returns non-zero if legal (king not left in check).

Definition at line 142 of file make_move.cpp.

References A1, A8, AddPiece(), ASSERT, C1, C8, CAPTURED, CastlePerm, S_BOARD::castlePerm, S_UNDO::castlePerm, ClearPiece(), D1, D8, EMPTY, S_BOARD::enPas, S_UNDO::enPas, F1, F8, FALSE, S_BOARD::fiftyMove, S_UNDO::fiftyMove, FROMSQ, G1, G8, H1, H8, HASH_CA, HASH_EP, HASH_SIDE, S_BOARD::hisPly, S_BOARD::history, isBoardStateValid(), isKing, isPawn, isSquareAttacked(), S_BOARD::KingSq, MAXDEPTH, MAXGAMEMOVES, MFLAGCA, MFLAGEP, MFLAGPS, S_UNDO::move, MovePiece(), NO_SQ, S_BOARD::pieces, pieceValueid(), S_BOARD::ply, S_BOARD::posKey, S_UNDO::posKey, PROMOTED, RANK_3, RANK_6, rankIndex120, S_BOARD::side, SideValid(), SqOnBoard(), takeMove(), TOSQ, TRUE, and WHITE.

Referenced by LegalMovesFrom(), moveExists(), Perft(), and PerftTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeNullMove()

void makeNullMove ( S_BOARD * board)

Make a null move (side to move toggles, no pieces moved).

Definition at line 303 of file make_move.cpp.

References ASSERT, S_BOARD::castlePerm, S_UNDO::castlePerm, S_BOARD::enPas, S_UNDO::enPas, S_BOARD::fiftyMove, S_UNDO::fiftyMove, HASH_EP, HASH_SIDE, S_BOARD::hisPly, S_BOARD::history, isBoardStateValid(), isSquareAttacked(), S_BOARD::KingSq, MAXDEPTH, MAXGAMEMOVES, S_UNDO::move, NO_SQ, NOMOVE, S_BOARD::ply, S_BOARD::posKey, S_UNDO::posKey, and S_BOARD::side.

Here is the call graph for this function:

◆ MovePiece()

void MovePiece ( const int from,
const int to,
S_BOARD * board )
static

Definition at line 99 of file make_move.cpp.

References ASSERT, BOTH, CLRBIT, EMPTY, HASH_PCE, isBigPiece, S_BOARD::pawns, S_BOARD::pceNum, pieceColor, S_BOARD::pieces, pieceValueid(), S_BOARD::pList, SETBIT, SideValid(), SQ64, and SqOnBoard().

Referenced by makeMove(), and takeMove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ takeMove()

void takeMove ( S_BOARD * board)

Undo the last made move.

Definition at line 240 of file make_move.cpp.

References A1, A8, AddPiece(), ASSERT, bP, C1, C8, CAPTURED, S_BOARD::castlePerm, S_UNDO::castlePerm, ClearPiece(), D1, D8, EMPTY, S_BOARD::enPas, S_UNDO::enPas, F1, F8, FALSE, S_BOARD::fiftyMove, S_UNDO::fiftyMove, FROMSQ, G1, G8, H1, H8, HASH_CA, HASH_EP, HASH_SIDE, S_BOARD::hisPly, S_BOARD::history, isBoardStateValid(), isKing, isPawn, S_BOARD::KingSq, MAXDEPTH, MAXGAMEMOVES, MFLAGCA, MFLAGEP, S_UNDO::move, MovePiece(), NO_SQ, pieceColor, S_BOARD::pieces, pieceValueid(), S_BOARD::ply, PROMOTED, S_BOARD::side, SqOnBoard(), TOSQ, WHITE, and wP.

Referenced by LegalMovesFrom(), makeMove(), moveExists(), Perft(), and PerftTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ takeNullMove()

void takeNullMove ( S_BOARD * board)

Undo the last null move.

Definition at line 327 of file make_move.cpp.

References ASSERT, S_BOARD::castlePerm, S_UNDO::castlePerm, S_BOARD::enPas, S_UNDO::enPas, S_BOARD::fiftyMove, S_UNDO::fiftyMove, HASH_EP, HASH_SIDE, S_BOARD::hisPly, S_BOARD::history, isBoardStateValid(), MAXDEPTH, MAXGAMEMOVES, NO_SQ, S_BOARD::ply, and S_BOARD::side.

Here is the call graph for this function:

Variable Documentation

◆ CastlePerm

const int CastlePerm[120]
Initial value:
= {
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 13, 15, 15, 15, 12, 15, 15, 14, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 7, 15, 15, 15, 3, 15, 15, 11, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15
}

Castling permission mask by board square (mailbox 120).

Definition at line 14 of file make_move.cpp.

Referenced by makeMove().