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

Go to the source code of this file.

Functions

bool isSquareAttacked (const int square, const int side, const S_BOARD *pos)
 Determines if a given square is attacked by a given side.

Variables

const int knightDirection [8] = { -8, -19, -21, -12, 8, 19, 21, 12 }
 Knight movement directions in 120-square board representation.
const int rookDirection [4] = { -1, -10, 1, 10 }
 Rook movement directions in 120-square board representation.
const int bishopDirection [4] = { -9, -11, 11, 9 }
 Bishop movement directions in 120-square board representation.
const int kingDirection [8] = { -1, -10, 1, 10, -9, -11, 11, 9 }
 King movement directions in 120-square board representation.

Function Documentation

◆ isSquareAttacked()

bool isSquareAttacked ( int sq,
int side,
const S_BOARD * pos )

Determines if a given square is attacked by a given side.

Parameters
sqSquare index (120-based representation).
sideSide to check for attacks (WHITE or BLACK).
posPointer to the current board state.
Returns
true if the square is attacked by the given side, false otherwise.

Definition at line 9 of file attack.cpp.

References ASSERT, bishopDirection, bP, EMPTY, isBoardStateValid(), IsBQ, IsKi, IsKn, IsRQ, kingDirection, knightDirection, OFFBOARD, PceValidEmptyOffbrd(), pieceColor, S_BOARD::pieces, rookDirection, SideValid(), SqIs120(), SqOnBoard(), WHITE, and wP.

Referenced by generateAllMoves(), makeMove(), and makeNullMove().

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

Variable Documentation

◆ bishopDirection

const int bishopDirection[4] = { -9, -11, 11, 9 }

Bishop movement directions in 120-square board representation.

Definition at line 6 of file attack.cpp.

Referenced by isSquareAttacked().

◆ kingDirection

const int kingDirection[8] = { -1, -10, 1, 10, -9, -11, 11, 9 }

King movement directions in 120-square board representation.

Definition at line 7 of file attack.cpp.

Referenced by isSquareAttacked().

◆ knightDirection

const int knightDirection[8] = { -8, -19, -21, -12, 8, 19, 21, 12 }

Knight movement directions in 120-square board representation.

Definition at line 4 of file attack.cpp.

Referenced by isSquareAttacked().

◆ rookDirection

const int rookDirection[4] = { -1, -10, 1, 10 }

Rook movement directions in 120-square board representation.

Definition at line 5 of file attack.cpp.

Referenced by isSquareAttacked().