-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.h
98 lines (77 loc) · 3.06 KB
/
board.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef __BOARD_H__
#define __BOARD_H__
#include <string>
#include "bitmanip.h"
using namespace std;
/* Prints a board */
void printBoard(Board *b);
/* Construct an empty board */
void emptyBoard(Board *b);
/* This is expensive -- only use for debugging */
bool equalBoard(Board *b1, Board *b2);
/* Returns true iff m1 and m2 are the same */
bool equalMove(Move m1, Move m2);
/* Returns the number of pieces on the board */
int getPieceCount(Board *b);
/* Rotate and/or flip the board as specified. Does not change the side to move. */
void transformBoard(Board *b, int tr);
/* Changes sides by flipping the board N-S and changing the color of all the pieces */
void changeSides(Board *b);
/* Changes sides if needed for an EGTB lookup (e.g. Black has more pieces than White) */
/* wp, bp: popcounts (saves recomputing them inside the function) */
void changeSidesIfNeeded(Board *b, int wp, int bp);
/* Two things need to happen before we refer to the EP index:
* 1. Naturally, the EP bit must be set
* 2. There needs to be a pawn that can execute the EP capture. We don't index boards where this isn't the case,
* because the result is identical to the non-EP position. */
inline bool epCapturePossible(Board *b) {
if (!b->bb[BB_EP]) {
return false;
}
if (b->side == WHITE) {
return b->bb[BB_WP] & RANK_5 & ((b->bb[BB_EP] >> 9) ^ (b->bb[BB_EP] >> 7));
} else {
return b->bb[BB_BP] & RANK_4 & ((b->bb[BB_EP] << 9) ^ (b->bb[BB_EP] << 7));
}
}
/* Returns true iff m is a capture on b (in which case any legal move on b is a capture) */
bool isCapture(Board *b, Move m);
/**
* Tranform the board as needed to bring it into its canonical position.
*
* @param bool dryRun If true, leave the board unchanged.
* @return int The transformation performed to canonicalize the board (which
* can be TR_NONE if the board is already canonical).
*/
int canonicalizeBoard(PieceSet *ps, int nps, Board *b, bool dryRun);
/**
* Constructs a board from a FEN string.
* @return True on success, false on failure.
*/
bool fenToBoard(const char* fen, Board* b);
/* Get the FEN notation for a board */
string boardToFen(Board *b);
/* Get the algebraic notation for every move on this board. This is best done for all the moves at once, because there can be ambiguities.
m is the array of all moves possible on the given board. */
void getAlgebraicNotation(Board *b, Move *m, int numMoves, string *san);
/* Returns a move's algebraic notation. This is *slow*. It works by generating
all the moves on board b, then all those moves' names. */
string getMoveName(Board* b, Move m);
/**
* Returns a move's long notation. This is useful when the board is
* unavailable.
*/
string getLongMoveName(Move m);
/* Make move m on the board b, modifying b */
void makeMove(Board *b, Move m);
/* Make backward move m on the board b, modifying b. See the remarks for getAllMoves() (no un-captures, no un-promotions etc.) */
void makeBackwardMove(Board *b, Move m);
/**
* Encodes a move on 16 bits.
*/
u16 encodeMove(Move m);
/**
* Decodes a 16-bit number into a move.
*/
Move decodeMove(u16 x);
#endif