Chess Engine
C++ chess engine with movegen, bitboards, and Arduino-friendly docs
Loading...
Searching...
No Matches
validate.cpp
Go to the documentation of this file.
1// validate.cpp
2#include <cstdio>
3#include "defs.h"
4#include "util/setup.h"
5#include "validate.h"
6
7int MoveListOk(const S_MOVELIST* moves, const S_BOARD* board) {
8 if (moves->count < 0 || moves->count >= MAXPOSITIONMOVES) return FALSE;
9
10 for (int i = 0; i < moves->count; ++i) {
11 const int m = moves->moves[i].move;
12 const int from = FROMSQ(m);
13 const int to = TOSQ(m);
14
15 if (!SqOnBoard(from) || !SqOnBoard(to)) return FALSE;
16 if (!pieceValueidEmpty(board->pieces[from])) return FALSE;
17 }
18 return TRUE;
19}
20
21int SqIs120(const int sq) {
22 return (sq >= 0 && sq < BRD_SQ_NUM);
23}
24
25int PceValidEmptyOffbrd(const int pce) {
26 return (pce == OFFBOARD) || (pce >= EMPTY && pce <= bK);
27}
28
29int SqOnBoard(const int sq) {
30 // fileIndex120[sq] is OFFBOARD for the 120-mailbox border
31 return (sq >= 0 && sq < BRD_SQ_NUM) && (fileIndex120[sq] != OFFBOARD);
32}
33
34int SideValid(const int side) {
35 return (side == WHITE || side == BLACK);
36}
37
38int FileRankValid(const int fr) {
39 return (fr >= 0 && fr <= 7);
40}
41
42int pieceValueidEmpty(const int pce) {
43 return (pce >= EMPTY && pce <= bK);
44}
45
46int pieceValueid(const int pce) {
47 return (pce >= wP && pce <= bK);
48}
49
#define TOSQ(m)
Definition defs.h:165
@ EMPTY
Definition defs.h:40
@ bK
Definition defs.h:40
@ wP
Definition defs.h:40
@ WHITE
Definition defs.h:44
@ BLACK
Definition defs.h:44
#define MAXPOSITIONMOVES
Definition defs.h:32
#define BRD_SQ_NUM
Definition defs.h:29
#define FROMSQ(m)
Definition defs.h:164
@ OFFBOARD
Definition defs.h:54
@ FALSE
Definition defs.h:57
@ TRUE
Definition defs.h:57
int fileIndex120[BRD_SQ_NUM]
File and rank lookup tables for each square (120-based).
Definition setup.cpp:26
int pieces[BRD_SQ_NUM]
Definition defs.h:102
int move
Definition defs.h:62
int count
Definition defs.h:68
S_MOVE moves[MAXPOSITIONMOVES]
Definition defs.h:67
int SqIs120(const int sq)
Checks if a given square index is within the 120-based range.
Definition validate.cpp:21
int MoveListOk(const S_MOVELIST *moves, const S_BOARD *board)
Validates that a move list is within bounds and references valid moves.
Definition validate.cpp:7
int PceValidEmptyOffbrd(const int pce)
Checks if the given piece code is empty, valid, or OFFBOARD.
Definition validate.cpp:25
int FileRankValid(const int fr)
Checks if a file or rank index is valid (0–7).
Definition validate.cpp:38
int pieceValueidEmpty(const int pce)
Checks if the given piece code is either empty or a valid piece.
Definition validate.cpp:42
int pieceValueid(const int pce)
Checks if the given piece code is a valid piece (non-empty).
Definition validate.cpp:46
int SqOnBoard(const int sq)
Checks if a given square index refers to a valid on-board square.
Definition validate.cpp:29
int SideValid(const int side)
Checks if the given side identifier is valid.
Definition validate.cpp:34