Chess Engine
C++ chess engine with movegen, bitboards, and Arduino-friendly docs
Loading...
Searching...
No Matches
move_generator.h File Reference
#include "../defs.h"
Include dependency graph for move_generator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MOVE(f, t, ca, pro, fl)
 Macro to encode a move into an integer.
#define SQOFFBOARD(sq)
 Macro to check if a square index is off the board.

Functions

void InitMvvLva (void)
 Initialize the MVV-LVA capture scoring table.
void generateAllMoves (const S_BOARD *pos, S_MOVELIST *list)
 Generate all pseudo-legal moves for the side to move.
void generateAllCaptures (const S_BOARD *pos, S_MOVELIST *list)
 Generate all pseudo-legal capture moves (including en passant).
int moveExists (S_BOARD *pos, int move)
 Check if a given move exists in the current position.

Variables

const int LoopSlidePce [8]
 Sliding piece loop order for move generation.
const int LoopNonSlidePce [6]
 Non-sliding piece loop order for move generation.
const int LoopSlideIndex [2]
 Indices into LoopSlidePce for white and black.
const int LoopNonSlideIndex [2]
 Indices into LoopNonSlidePce for white and black.
const int pieceDirection [13][8]
 Direction offsets for each piece type.
const int numberDirections [13]
 Number of valid directions for each piece type.
const int VictimScore [13]
 Victim scoring table for MVV-LVA.
int MvvLvaScores [13][13]
 Most Valuable Victim / Least Valuable Attacker scores.

Macro Definition Documentation

◆ MOVE

#define MOVE ( f,
t,
ca,
pro,
fl )
Value:
( (f) | ((t) << 7) | ((ca) << 14) | ((pro) << 20) | (fl) )

Macro to encode a move into an integer.

Definition at line 7 of file move_generator.h.

Referenced by AddBlackPawnCapMove(), AddBlackPawnMove(), AddWhitePawnCapMove(), AddWhitePawnMove(), generateAllCaptures(), and generateAllMoves().

◆ SQOFFBOARD

#define SQOFFBOARD ( sq)
Value:
@ OFFBOARD
Definition defs.h:54
int fileIndex120[BRD_SQ_NUM]
File and rank lookup tables for each square (120-based).
Definition setup.cpp:26

Macro to check if a square index is off the board.

Definition at line 10 of file move_generator.h.

Referenced by generateAllCaptures(), and generateAllMoves().

Function Documentation

◆ generateAllCaptures()

void generateAllCaptures ( const S_BOARD * pos,
S_MOVELIST * list )
extern

Generate all pseudo-legal capture moves (including en passant).

Parameters
posPointer to the current board position.
listPointer to the move list to be filled.

Definition at line 299 of file move_generator.cpp.

References AddBlackPawnCapMove(), AddCaptureMove(), AddEnPassantMove(), AddWhitePawnCapMove(), ASSERT, BLACK, bP, S_MOVELIST::count, EMPTY, S_BOARD::enPas, isBoardStateValid(), LoopNonSlideIndex, LoopNonSlidePce, LoopSlideIndex, LoopSlidePce, MFLAGEP, MOVE, MoveListOk(), NO_SQ, numberDirections, S_BOARD::pceNum, pieceColor, pieceDirection, S_BOARD::pieces, pieceValueid(), S_BOARD::pList, S_BOARD::side, SQOFFBOARD, SqOnBoard(), WHITE, and wP.

Here is the call graph for this function:

◆ generateAllMoves()

void generateAllMoves ( const S_BOARD * pos,
S_MOVELIST * list )
extern

Generate all pseudo-legal moves for the side to move.

Parameters
posPointer to the current board position.
listPointer to the move list to be filled.

Definition at line 165 of file move_generator.cpp.

References AddBlackPawnCapMove(), AddBlackPawnMove(), AddCaptureMove(), AddEnPassantMove(), AddQuietMove(), AddWhitePawnCapMove(), AddWhitePawnMove(), ASSERT, B1, B8, BKCA, BLACK, bP, BQCA, C1, C8, S_BOARD::castlePerm, S_MOVELIST::count, D1, D8, E1, E8, EMPTY, S_BOARD::enPas, F1, F8, G1, G8, isBoardStateValid(), isSquareAttacked(), LoopNonSlideIndex, LoopNonSlidePce, LoopSlideIndex, LoopSlidePce, MFLAGCA, MFLAGEP, MFLAGPS, MOVE, MoveListOk(), NO_SQ, numberDirections, S_BOARD::pceNum, pieceColor, pieceDirection, S_BOARD::pieces, pieceValueid(), S_BOARD::pList, RANK_2, RANK_7, rankIndex120, S_BOARD::side, SQOFFBOARD, SqOnBoard(), WHITE, WKCA, wP, and WQCA.

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

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

◆ InitMvvLva()

void InitMvvLva ( void )
extern

Initialize the MVV-LVA capture scoring table.

Note
Call once at engine startup before generating moves.

Definition at line 141 of file move_generator.cpp.

References bK, MvvLvaScores, VictimScore, and wP.

Referenced by initializeEngine().

Here is the caller graph for this function:

◆ moveExists()

int moveExists ( S_BOARD * pos,
int move )
extern

Check if a given move exists in the current position.

Parameters
posPointer to the current board position.
moveEncoded move integer.
Returns
Non-zero if the move exists; zero otherwise.

Definition at line 149 of file move_generator.cpp.

References S_MOVELIST::count, FALSE, generateAllMoves(), makeMove(), S_MOVE::move, S_MOVELIST::moves, takeMove(), and TRUE.

Here is the call graph for this function:

Variable Documentation

◆ LoopNonSlideIndex

const int LoopNonSlideIndex[2]
extern

Indices into LoopNonSlidePce for white and black.

Definition at line 10 of file move_generator.cpp.

Referenced by generateAllCaptures(), and generateAllMoves().

◆ LoopNonSlidePce

const int LoopNonSlidePce[6]
extern

Non-sliding piece loop order for move generation.

Definition at line 8 of file move_generator.cpp.

Referenced by generateAllCaptures(), and generateAllMoves().

◆ LoopSlideIndex

const int LoopSlideIndex[2]
extern

Indices into LoopSlidePce for white and black.

Definition at line 9 of file move_generator.cpp.

Referenced by generateAllCaptures(), and generateAllMoves().

◆ LoopSlidePce

const int LoopSlidePce[8]
extern

Sliding piece loop order for move generation.

Definition at line 7 of file move_generator.cpp.

Referenced by generateAllCaptures(), and generateAllMoves().

◆ MvvLvaScores

int MvvLvaScores[13][13]
extern

Most Valuable Victim / Least Valuable Attacker scores.

◆ numberDirections

const int numberDirections[13]
extern

Number of valid directions for each piece type.

Definition at line 28 of file move_generator.cpp.

Referenced by generateAllCaptures(), and generateAllMoves().

◆ pieceDirection

const int pieceDirection[13][8]
extern

Direction offsets for each piece type.

Definition at line 12 of file move_generator.cpp.

Referenced by generateAllCaptures(), and generateAllMoves().

◆ VictimScore

const int VictimScore[13]
extern

Victim scoring table for MVV-LVA.

Definition at line 30 of file move_generator.cpp.

Referenced by InitMvvLva().