31typedef std::uint32_t matSigT;
60#define MASK_BP 0x0000000F
61#define MASK_BN 0x00000030
62#define MASK_BB 0x000000C0
63#define MASK_BR 0x00000300
64#define MASK_BQ 0x00000C00
65#define MASK_WP 0x0000F000
66#define MASK_WN 0x00030000
67#define MASK_WB 0x000C0000
68#define MASK_WR 0x00300000
69#define MASK_WQ 0x00C00000
114#define MATSIG_FlipColor(x) ((x) >> 12) | (((x) & 0x00000FFF) << 12)
119#define MATSIG_Has_WQ(x) ((x) & MASK_WQ)
120#define MATSIG_Has_BQ(x) ((x) & MASK_BQ)
121#define MATSIG_Has_WR(x) ((x) & MASK_WR)
122#define MATSIG_Has_BR(x) ((x) & MASK_BR)
123#define MATSIG_Has_WB(x) ((x) & MASK_WB)
124#define MATSIG_Has_BB(x) ((x) & MASK_BB)
125#define MATSIG_Has_WN(x) ((x) & MASK_WN)
126#define MATSIG_Has_BN(x) ((x) & MASK_BN)
127#define MATSIG_Has_WP(x) ((x) & MASK_WP)
128#define MATSIG_Has_BP(x) ((x) & MASK_BP)
130#define MATSIG_HasQueens(x) ((x) & (MASK_WQ | MASK_BQ))
131#define MATSIG_HasRooks(x) ((x) & (MASK_WR | MASK_BR))
132#define MATSIG_HasBishops(x) ((x) & (MASK_WB | MASK_BB))
133#define MATSIG_HasKnights(x) ((x) & (MASK_WN | MASK_BN))
134#define MATSIG_HasPawns(x) ((x) & (MASK_WP | MASK_BP))
139#define MATSIG_Count_WQ(x) (((x) & MASK_WQ) >> SHIFT_WQ)
140#define MATSIG_Count_BQ(x) (((x) & MASK_BQ) >> SHIFT_BQ)
141#define MATSIG_Count_WR(x) (((x) & MASK_WR) >> SHIFT_WR)
142#define MATSIG_Count_BR(x) (((x) & MASK_BR) >> SHIFT_BR)
143#define MATSIG_Count_WB(x) (((x) & MASK_WB) >> SHIFT_WB)
144#define MATSIG_Count_BB(x) (((x) & MASK_BB) >> SHIFT_BB)
145#define MATSIG_Count_WN(x) (((x) & MASK_WN) >> SHIFT_WN)
146#define MATSIG_Count_BN(x) (((x) & MASK_BN) >> SHIFT_BN)
147#define MATSIG_Count_WP(x) (((x) & MASK_WP) >> SHIFT_WP)
148#define MATSIG_Count_BP(x) (((x) & MASK_BP) >> SHIFT_BP)
154inline scid::core::uint
155matsig_getCount (matSigT m, scid::core::pieceT p)
157 return (m & MASK_BY_PIECE[p]) >> SHIFT_BY_PIECE[p];
165matsig_setCount (matSigT m, scid::core::pieceT p, scid::core::uint count)
168 m &= ~(MASK_BY_PIECE[p]);
171 if (p != scid::core::PAWN && count > 3)
175 m |= ((scid::core::uint) count) << SHIFT_BY_PIECE[p];
182const matSigT MATSIG_Empty = 0;
184const matSigT MATSIG_StdStart =
185 ((1 << SHIFT_WQ) | (1 << SHIFT_BQ) | (2 << SHIFT_WR) | (2 << SHIFT_BR) |
186 (2 << SHIFT_WB) | (2 << SHIFT_BB) | (2 << SHIFT_WN) | (2 << SHIFT_BN) |
187 (8 << SHIFT_WP) | (8 << SHIFT_BP));
197matsig_makeString (matSigT matsig);
214matsig_isReachable (matSigT mStart, matSigT mTarget,
bool promos,
bool upromo);
219matsig_isReachablePawns (matSigT mStart, matSigT mTarget)
221 if (MATSIG_Count_WP(mStart) < MATSIG_Count_WP(mTarget)) {
return false; }
222 if (MATSIG_Count_BP(mStart) < MATSIG_Count_BP(mTarget)) {
return false; }
231inline matSigT matsig_Make(
const scid::core::byte* materialCounts) {
233 m |= std::min<matSigT>(3, materialCounts[scid::core::WQ]) << SHIFT_WQ;
234 m |= std::min<matSigT>(3, materialCounts[scid::core::WR]) << SHIFT_WR;
235 m |= std::min<matSigT>(3, materialCounts[scid::core::WB]) << SHIFT_WB;
236 m |= std::min<matSigT>(3, materialCounts[scid::core::WN]) << SHIFT_WN;
237 m |= matSigT(materialCounts[scid::core::WP]) << SHIFT_WP;
238 m |= std::min<matSigT>(3, materialCounts[scid::core::BQ]) << SHIFT_BQ;
239 m |= std::min<matSigT>(3, materialCounts[scid::core::BR]) << SHIFT_BR;
240 m |= std::min<matSigT>(3, materialCounts[scid::core::BB]) << SHIFT_BB;
241 m |= std::min<matSigT>(3, materialCounts[scid::core::BN]) << SHIFT_BN;
242 m |= matSigT(materialCounts[scid::core::BP]) << SHIFT_BP;
251const scid::core::uint
254const scid::core::uint
255HPSIG_StdStart = 0xFFFF;
259hpSig_PossibleMatch (scid::core::uint hpSig,
const scid::core::byte * changeList);
262hpSig_Prefix (
const scid::core::byte * changeListA,
const scid::core::byte * changeListB);
265hpSig_Final (
const scid::core::byte * changeList);
269static const scid::core::uint hpSig_bitMask [16] = {
271 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
273 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
276inline scid::core::uint
277hpSig_AddPawn (scid::core::uint hpSig, scid::core::colorT color, scid::core::fyleT fyle)
279 assert(color == scid::core::WHITE || color == scid::core::BLACK);
280 assert(fyle <= scid::core::H_FYLE);
282 scid::core::uint val = (scid::core::uint) fyle;
283 if (color == scid::core::BLACK) val += 8;
284 return hpSig | hpSig_bitMask [val];
287inline scid::core::uint
288hpSig_ClearPawn (scid::core::uint hpSig, scid::core::colorT color, scid::core::fyleT fyle)
290 assert(color == scid::core::WHITE || color == scid::core::BLACK);
291 assert(fyle <= scid::core::H_FYLE);
293 scid::core::uint val = (scid::core::uint) fyle;
294 if (color == scid::core::BLACK) val += 8;
295 return hpSig & ~(hpSig_bitMask [val]);
304inline std::pair<std::uint16_t, std::uint16_t>
hpSig_make(
const scid::core::pieceT* board) {
307 const scid::core::pieceT* b = board + scid::core::A2;
309 if (*b != scid::core::WP) { hpSig |= 0x8000; ++nMoved; } b++;
310 if (*b != scid::core::WP) { hpSig |= 0x4000; ++nMoved; } b++;
311 if (*b != scid::core::WP) { hpSig |= 0x2000; ++nMoved; } b++;
312 if (*b != scid::core::WP) { hpSig |= 0x1000; ++nMoved; } b++;
313 if (*b != scid::core::WP) { hpSig |= 0x0800; ++nMoved; } b++;
314 if (*b != scid::core::WP) { hpSig |= 0x0400; ++nMoved; } b++;
315 if (*b != scid::core::WP) { hpSig |= 0x0200; ++nMoved; } b++;
316 if (*b != scid::core::WP) { hpSig |= 0x0100; ++nMoved; }
317 b = board + scid::core::A7;
318 if (*b != scid::core::BP) { hpSig |= 0x0080; ++nMoved; } b++;
319 if (*b != scid::core::BP) { hpSig |= 0x0040; ++nMoved; } b++;
320 if (*b != scid::core::BP) { hpSig |= 0x0020; ++nMoved; } b++;
321 if (*b != scid::core::BP) { hpSig |= 0x0010; ++nMoved; } b++;
322 if (*b != scid::core::BP) { hpSig |= 0x0008; ++nMoved; } b++;
323 if (*b != scid::core::BP) { hpSig |= 0x0004; ++nMoved; } b++;
324 if (*b != scid::core::BP) { hpSig |= 0x0002; ++nMoved; } b++;
325 if (*b != scid::core::BP) { hpSig |= 0x0001; ++nMoved; }
328 return {
static_cast<std::uint16_t
>(hpSig),
static_cast<std::uint16_t
>(nMoved)};
331inline bool hpSig_match(
int hpSig,
int nMoved,
const scid::core::byte* changeList) {
334 if (*changeList == 16 && nMoved == 16)
336 if (*changeList++ < nMoved)
340 for (
int i = 0, n = nMoved / 2; i < n; ++i) {
341 sig |= 1 << (*changeList >> 4);
342 sig |= 1 << (*changeList++ & 0x0F);
345 sig |= 1 << (*changeList >> 4);
Chess board constants, piece helpers, square geometry, and directions.
class StrRange - parse a string interpreting its content as 1 or 2 integers separated by whitespace.
Definition common.h:30
std::pair< std::uint16_t, std::uint16_t > hpSig_make(const scid::core::pieceT *board)
Creates a 16-bits bitmap of the missing pawns in the home ranks.
Definition matsig.h:304