Belofte version 2.1.9
A promising chess program using the UCI or Winboard interface
basicboard.cpp
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: basicboard.cpp
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#include "belofte.h"
9
10//-----------------------------------------------------------------------
11
12#if defined(__GNUC__)
13#pragma GCC diagnostic push
14#pragma GCC diagnostic ignored "-Weffc++"
15#endif
16
18 : m_boardInfo{0ULL}
19{
20 memset(m_fields, 0, sizeof(m_fields));
21
22 // parse
23 std::string sFen = belofte::alltrim(fen); // remove leading and trailing space
24 belofte::stringList const fenParts = belofte::stringSplit(sFen, " ");
25 belofte::stringList const rowParts = belofte::stringSplit(fenParts[0], "/");
26
27 // part 1, board filler
28 for (rank_t iRank = 0; iRank < 8; ++iRank) {
29 auto initRank = [this](rank_t iR, std::string const& rankdata) -> void {
30 column_t iCol = 0;
31 unsigned int i = 0;
32 while (iCol < 8) {
33 unsigned char c = static_cast<unsigned char>(rankdata[i++]);
34 if (c == 0) {
35 break;
36 } else if ((c >= '1') && (c <= '8')) {
37 iCol += (c - '0');
38 } else {
39 setPieceKU(bCase::coordToCase(iCol, iR), bPiece::getPiece(static_cast<cpiece_t>(c)));
40 ++iCol;
41 }
42 }
43 };
44 initRank(7 - iRank, rowParts[static_cast<unsigned long>(iRank)]);
45 }
46
47 if (fenParts.size() > 2) {
48 // part 3, castling rights
49 setCastleRights(tCFlags::WCASTLE_S, fenParts[2].find('K') != std::string::npos);
50 setCastleRights(tCFlags::WCASTLE_L, fenParts[2].find('Q') != std::string::npos);
51 setCastleRights(tCFlags::BCASTLE_S, fenParts[2].find('k') != std::string::npos);
52 setCastleRights(tCFlags::BCASTLE_L, fenParts[2].find('q') != std::string::npos);
53 }
54
55 if (fenParts.size() > 3) {
56 // part 4, ep case
57 if (fenParts[3] == "-") {
58 clearEp();
59 } else {
60 setEp(bCase(fenParts[3]).getCaseT());
61 }
62 }
63
64 if (fenParts.size() > 4) {
65 // part 5, 50 move number (half-move / ply)
66 setPly50Moves(static_cast<movenum50_t>(atoi(fenParts[4].c_str())));
67 }
68
69 if (fenParts.size() > 5) {
70 // part 6, move number, starting from 1
71 setPly(static_cast<plynum_t>((atoi(fenParts[5].c_str()) - 1) * 2));
72 }
73
74 if (fenParts.size() > 1) {
75 // part 2, side to move
76 if (fenParts[1] == "b") incPly();
77 }
78
79 /**
80 @todo check legality of position: Max number of pieces
81 of each type e.g. K=1, Q=(9 - # pawns), N=(10 - # pawns)
82 colour of bishops, double in-check, in case of ep, adjacent pawn
83 movenumber if not initial position, location of pawns,
84 position of king and rooks in case of castle allowed (att. 960)
85 for each promoted piece, an opponent piece must have been taken
86 */
87 calcHash();
88}
89
90#if defined(__GNUC__)
91#pragma GCC diagnostic pop
92#endif
93
94//-----------------------------------------------------------------------
95
97{
98 std::string strfen;
99 piece_t nPiece;
100 std::string castl;
101
102 // part 1, board filler
103 for (rank_t iRank = 0; iRank < 8; ++iRank) {
104 int iBlanks = 0;
105 for (column_t iCol = 0; iCol < 8; ++iCol) {
106 nPiece = getPiece(iCol, 7 - iRank);
107 if (nPiece) {
108 if (iBlanks) strfen += static_cast<char>(iBlanks + '0');
109 iBlanks = 0;
110 strfen += static_cast<char>(bPiece::getPieceChar(nPiece));
111 } else {
112 ++iBlanks;
113 }
114 }
115 if (iBlanks) strfen += static_cast<char>(iBlanks + '0');
116 if (iRank < 7) strfen += "/";
117 }
118
119 strfen += getColourToMove() == tSide::SIDE_BLACK ? " b " : " w ";
120
121 castl += hasCastleRights(tCFlags::WCASTLE_S) ? "K" : "";
122 castl += hasCastleRights(tCFlags::WCASTLE_L) ? "Q" : "";
123 castl += hasCastleRights(tCFlags::BCASTLE_S) ? "k" : "";
124 castl += hasCastleRights(tCFlags::BCASTLE_L) ? "q" : "";
125 strfen += castl.size() ? castl : "-";
126
127 if (isEpSet()) {
128 strfen += " " + std::string(bCase(getEp())) + " ";
129 } else {
130 strfen += " - ";
131 }
133
134 return bFen(strfen);
135}
136
137//-----------------------------------------------------------------------
138
139/**
140 * set ep case, it will actually be stored as column only
141 * rank will be calculated based on side to move
142 * function is never called to clear ep case or when ep is not set
143 */
145{
146 if (isEpSet()) {
147 // ep case was already set, change it
148 // flag does not need to be changed
149 // clear hash of old ep field
151 m_boardInfo.s_boardInfo.capturedpiece &= 0x8F;
152 } else {
153 // set flag
154 m_boardInfo.s_boardInfo.capturedpiece |= 0x80;
155 }
156
157 m_boardInfo.s_boardInfo.capturedpiece |= bCase::column(e) << 4;
158
159 // update hash
161}
162
164{
165 if (isEpSet()) {
167 // clear flag and ep column
168 m_boardInfo.s_boardInfo.capturedpiece &= 0x0F;
169 }
170}
171
172//-----------------------------------------------------------------------
173
174void bBasicBoard::setCastleRights(uint8_t const f, bool const c)
175{
176 if (c) setCastleRights(f);
177 else clearCastleRights(f);
178}
179
180void bBasicBoard::setCastleRights(uint8_t const f)
181{
182 if (!(m_boardInfo.s_boardInfo.flags & f)) {
183 m_boardInfo.s_boardInfo.flags |= f;
184 /// there can be (is) a difference in the offsets in the hash table and the castle flags
185 /// @todo what happens if 2 rights are set together or one by one
186 m_hash ^= hashmultiplexer[tPiece::P_EMPTY][f];
187 }
188}
189
191{
192 if (m_boardInfo.s_boardInfo.flags & f) {
193 m_boardInfo.s_boardInfo.flags &= 0x0F & ~f; // make sure to align to 4 bits only
194 /// there can be (is) a difference in the offsets in the hash table and the castle flags
195 /// @todo what happens if 2 rights are cleared together or one by one
196 m_hash ^= hashmultiplexer[tPiece::P_EMPTY][f];
197 }
198}
199
200/**
201 * Clear castle flag if rook captured
202 * update piece counter, update hash, clear field
203 */
204void bBasicBoard::capturePieceOn(piece_t const capturedPiece, case_t const ct)
205{
206 setNonSilent();
207 setCapturedPiece(capturedPiece);
210 if (capturedPiece == tPiece::W_ROOK) {
211 if (ct == 7) {
213 } else if (ct == 0) {
215 }
216 } else if (capturedPiece == tPiece::B_ROOK) {
217 if (ct == 63) {
219 } else if (ct == 56) {
221 }
222 }
223}
224
225void bBasicBoard::movePiece(case_t const cf, case_t const ct, piece_t const np)
226{
227 m_fields[cf] = tPiece::P_EMPTY;
228 m_fields[ct] = np;
229 m_hash ^= hashmultiplexer[np][cf] ^ hashmultiplexer[np][ct];
230}
231
232void bBasicBoard::swapPiece(case_t const cf, piece_t const op, piece_t const np)
233{
234 m_fields[cf] = np;
235 m_hash ^= hashmultiplexer[op][cf] ^ hashmultiplexer[np][cf];
236}
237
238void bBasicBoard::clearPiece(case_t const cf, piece_t const op)
239{
240 m_fields[cf] = tPiece::P_EMPTY;
241 m_hash ^= hashmultiplexer[op][cf];
242}
243
245{
246 m_fields[cf] = op;
247 m_hash ^= hashmultiplexer[op][cf];
248}
249
251{
252 m_fields[cf] = tPiece::P_EMPTY;
253 m_fields[ct] = tPiece::W_KING;
255 m_boardInfo.s_boardInfo.whiteKing = ct;
256}
257
259{
260 m_fields[cf] = tPiece::P_EMPTY;
261 m_fields[ct] = tPiece::B_KING;
263 m_boardInfo.s_boardInfo.blackKing = ct;
264}
265
266//-----------------------------------------------------------------------
267
268/**
269 * Set hash based on board position, also calc pieces
270 * Byte 0: bits 4-6 capture count (masked)
271 * bit 7 player to move
272 * We are using 64 bits for hash
273 * @todo check increase to 64 bits, is there added value
274 */
276{
277 hashkey_t hash = HASH_INIT;
278 setPieceCount(0);
279 for (case_t iCase = 0; iCase < 64; ++iCase) {
280 int piece = getPiece(iCase);
281 if (piece) {
282 hash ^= hashmultiplexer[piece][iCase];
284 }
285 }
286
288 hash ^= hashmultiplexer[tPiece::P_EMPTY][static_cast<uint8_t>(tHSpecial::HP_CASTLE_FL) + static_cast<uint8_t>(tCFlags::WCASTLE_S)];
290 hash ^= hashmultiplexer[tPiece::P_EMPTY][static_cast<uint8_t>(tHSpecial::HP_CASTLE_FL) + static_cast<uint8_t>(tCFlags::WCASTLE_L)];
292 hash ^= hashmultiplexer[tPiece::P_EMPTY][static_cast<uint8_t>(tHSpecial::HP_CASTLE_FL) + static_cast<uint8_t>(tCFlags::BCASTLE_S)];
294 hash ^= hashmultiplexer[tPiece::P_EMPTY][static_cast<uint8_t>(tHSpecial::HP_CASTLE_FL) + static_cast<uint8_t>(tCFlags::BCASTLE_L)];
295
296 // use hash of field 0 or any of the ep fields
297 if (isEpSet()) hash ^= hashmultiplexer[tPiece::P_EMPTY][getEp()];
298
299 // set bit 63 (odd material)
300 if (pieceCount() & 0x01) hash |= HASH_ODDMATERIAL;
301
302 // set bit 64 (black to move)
304
305 m_hash = hash;
306}
307
308//-----------------------------------------------------------------------
309
310/**
311 * play game move on board
312 * @return boardinfo - of basicboard
313 */
315{
317 return applyWhiteMove(m);
318 }
319 return applyBlackMove(m);
320}
321
322//-----------------------------------------------------------------------
323
325{
326 // keep old flags
327 boardInfo_t oldBoardInfo(m_boardInfo.u_boardInfo);
328
329 case_t cf = m.from();
330 case_t ct = m.to();
331 piece_t piece = getPiece(cf);
332 piece_t capturedPiece = tPiece::P_EMPTY;
333
334 if (piece == tPiece::W_PAWN) {
335 if (m.isEPMove()) {
336 capturedPiece = tPiece::B_PAWN;
337 clearPiece(bCase::coordToCase(m.tocolumn(), m.fromrank()), capturedPiece);
338 } else if (m.isCapture()) {
339 capturedPiece = getPiece(ct);
340 clearPiece(ct, capturedPiece);
341 } else {
343 }
344 movePiece(cf, ct, tPiece::W_PAWN);
345 if (m.isPromotion()) {
347 clearEp(); // clear ep flag
348 } else {
349 if (m.isEPPossible()) {
350 /// @todo add functions such as nextrank
352 } else {
353 clearEp(); // clear ep flag
354 }
355 }
356 } else {
357 // other pieces: King, Queen, Rook, Knight, Bishop
358 clearEp(); // clear ep flag
359 if (m.isCapture()) {
360 capturedPiece = getPiece(ct);
361 clearPiece(ct, capturedPiece);
362 } else {
364 }
365 if (piece == tPiece::W_KING) {
366 moveWhiteKing(cf, ct);
367 if (m.isCastleMove()) {
368 if (m.isLongCastleMove()) {
370 } else {
372 }
374 }
377 } else {
378 movePiece(cf, ct, piece);
379 if (piece == tPiece::W_ROOK) {
380 if (cf == 0) {
382 } else if (cf == 7) {
384 }
385 }
386 }
387 }
388
389 /// @todo flag mate/stalemate move, special move, ...
390 if (m.isCheck()) {
391 setInCheck(); /// @todo check do we need to look for mate here ?
392 } else {
393 clearInCheck();
394 }
395 m_hash |= HASH_BLACKTOMOVE;
396
397 if (capturedPiece) {
398 capturePieceOn(capturedPiece, ct);
399 } else {
401 }
402 incPly();
403
404 return oldBoardInfo;
405}
406
408{
409 // keep old flags
410 boardInfo_t oldBoardInfo(m_boardInfo.u_boardInfo);
411
412 case_t cf = m.from();
413 case_t ct = m.to();
414 piece_t piece = getPiece(cf);
415 piece_t capturedPiece = tPiece::P_EMPTY;
416
417 if (piece == tPiece::B_PAWN) {
418 if (m.isEPMove()) {
419 capturedPiece = tPiece::W_PAWN;
420 clearPiece(bCase::coordToCase(m.tocolumn(), m.fromrank()), capturedPiece);
421 } else if (m.isCapture()) {
422 capturedPiece = getPiece(ct);
423 clearPiece(ct, capturedPiece);
424 } else {
426 }
427 movePiece(cf, ct, tPiece::B_PAWN);
428 if (m.isPromotion()) {
430 clearEp(); // clear ep flag
431 } else {
432 if (m.isEPPossible()) {
433 /// @todo add functions such as nextrank
435 } else {
436 clearEp(); // clear ep flag
437 }
438 }
439 } else {
440 // other pieces: King, Queen, Rook, Knight, Bishop
441 clearEp(); // clear ep flag
442 if (m.isCapture()) {
443 capturedPiece = getPiece(ct);
444 clearPiece(ct, capturedPiece);
445 } else {
447 }
448 if (piece == tPiece::B_KING) {
449 moveBlackKing(cf, ct);
450 if (m.isCastleMove()) {
451 if (m.isLongCastleMove()) {
452 movePiece(56, 59, tPiece::B_ROOK);
453 } else {
454 movePiece(63, 61, tPiece::B_ROOK);
455 }
457 }
460 } else {
461 movePiece(cf, ct, piece);
462 if (piece == tPiece::B_ROOK) {
463 if (cf == 56) {
465 } else if (cf == 63) {
467 }
468 }
469 }
470 }
471
472 /// @todo flag mate/stalemate move, special move, ...
473 if (m.isCheck()) {
474 setInCheck(); /// @todo check do we need to look for mate here ?
475 } else {
476 clearInCheck();
477 }
478 m_hash &= ~HASH_BLACKTOMOVE;
479
480 if (capturedPiece) {
481 capturePieceOn(capturedPiece, ct);
482 } else {
484 }
485 incPly();
486
487 return oldBoardInfo;
488}
489
490/**
491 * exact restoration of basic board using move details
492 */
493void bBasicBoard::unApplyMove(bMove const& m, boardInfo_t const oldBoardInfo)
494{
495 case_t ct = m.to();
496 case_t cf = m.from();
497
499 // when undoing move, we have not decreased ply yet, so
500 // colour to move is inverted
501 // tSide::SIDE_WHITE
502 if (m.isEPMove()) {
503 movePiece(ct, cf, tPiece::W_PAWN);
505 } else {
506 piece_t piece = getPiece(ct);
507 clearPiece(ct, piece);
508 if (getCapturedPiece()) {
510 }
511 if (m.isPromotion()) {
513 } else {
514 restorePiece(cf, piece);
515 if (m.isCastleMove()) {
516 if (m.isLongCastleMove()) {
518 } else {
519 // short un-castle
521 }
522 }
523 }
524 }
525 m_hash &= ~HASH_BLACKTOMOVE;
526 } else {
527 // tSide::SIDE_BLACK
528 if (m.isEPMove()) {
529 movePiece(ct, cf, tPiece::B_PAWN);
531 } else {
532 piece_t piece = getPiece(ct);
533 clearPiece(ct, piece);
534 if (getCapturedPiece()) {
536 }
537 if (m.isPromotion()) {
539 } else {
540 restorePiece(cf, piece);
541 if (m.isCastleMove()) {
542 if (m.isLongCastleMove()) {
543 movePiece(59, 56, tPiece::B_ROOK);
544 } else {
545 // short un-castle
546 movePiece(61, 63, tPiece::B_ROOK);
547 }
548 }
549 }
550 }
551 m_hash |= HASH_BLACKTOMOVE;
552 }
553 // set ply, kingpos, captured piece, castle flags, ...
554 m_boardInfo.u_boardInfo = oldBoardInfo.u_boardInfo;
555}
556
557/**
558 * apply move to check if in check only, board to be discarded
559 * as it will be in incomplete state, no hash update
560 * no check flag set, etc.
561 * promotion is not executed, pawn is kept at promotion place
562 * @param oldcol column from
563 * @param oldrank rank from
564 * @param newcol column to
565 * @param newrank rank to
566 * @return boardinfo and captured piece
567 */
569 column_t const newcol, rank_t const newrank)
570{
571 // keep old flags
572 boardInfo_t oldBoardInfo(m_boardInfo.u_boardInfo);
573
574 piece_t piece = removePiece(oldcol, oldrank); // clear from square
575
576 // in case of capture, we return captured piece
577 oldBoardInfo.setCapturedPiece(setGetPiece(newcol, newrank, piece));
578
580 if (piece == tPiece::W_PAWN) {
581 if (newcol != oldcol) {
582 // this is a column change, so a capture move
583 // check if we need to clear ep case
584 if (getPiece(newcol, newrank) == tPiece::P_EMPTY) {
585 // ep move, clear pawn
586 clearPiece(bCase::coordToCase(newcol, newrank-1));
587 oldBoardInfo.setCapturedPiece(tPiece::P_SIZE); // this is a special hack to allow
588 // unmake move to restore ep move
589 }
590 }
591 } else if (piece == tPiece::W_KING) {
592 m_boardInfo.s_boardInfo.whiteKing = bCase::coordToCase(newcol, newrank);
593 if ((newcol - oldcol) == 2) {
594 // short castle
595 clearPiece(7);
597 } else if ((newcol - oldcol) == -2) {
598 // long castle
599 clearPiece(0);
601 }
602 }
603 } else {
604 // tSide::SIDE_BLACK
605 if (piece == tPiece::B_PAWN) {
606 if (newcol != oldcol) {
607 // this is a column change, so a capture move
608 // check if we need to clear ep case
609 if (getPiece(newcol, newrank) == tPiece::P_EMPTY) {
610 // ep move, clear pawn
611 clearPiece(bCase::coordToCase(newcol, newrank+1));
612 oldBoardInfo.setCapturedPiece(tPiece::P_SIZE); // this is a special hack to allow
613 // unmake move to restore ep move
614 }
615 }
616 } else if (piece == tPiece::B_KING) {
617 m_boardInfo.s_boardInfo.blackKing = bCase::coordToCase(newcol, newrank);
618 if ((newcol - oldcol) == 2) {
619 // short castle
620 clearPiece(63);
622 } else if ((newcol - oldcol) == -2) {
623 // long castle
624 clearPiece(56);
626 }
627 }
628 }
629 incPly();
630 return oldBoardInfo;
631}
632
633/**
634 * undo makeBoardMove, restoring previous situation
635 * @param cf case from
636 * @param newcol column to
637 * @param newrank rank to
638 * @param oldBoardInfo the boardInfo of the old position
639 * Note: does not undo promotion properly
640 */
642 column_t const newcol, rank_t const newrank,
643 boardInfo_t const oldBoardInfo)
644{
645 case_t ct = bCase::coordToCase(newcol, newrank);
646 piece_t piece = getPiece(ct);
647
648 setPiece(cf, piece);
649 if ((oldBoardInfo.s_boardInfo.capturedpiece & 0x0F) == tPiece::P_SIZE) {
650 // see remark on e.p move, we flag old piece as P_SIZE
651 // to be able to restore board on before ep move
652 clearPiece(ct);
654 setPiece(bCase::coordToCase(newcol, newrank-1), tPiece::W_PAWN);
655 } else {
656 // tSide::SIDE_BLACK
657 setPiece(bCase::coordToCase(newcol, newrank+1), tPiece::B_PAWN);
658 }
659 } else {
660 setPiece(ct, (oldBoardInfo.s_boardInfo.capturedpiece & 0x0F)); // can be tPiece::P_EMPTY as well
662 if (piece == tPiece::W_KING) {
663 m_boardInfo.s_boardInfo.whiteKing = cf;
664 column_t oldcol = bCase::column(cf);
665 if ((newcol - oldcol) == 2) {
666 // short un-castle
668 clearPiece(5);
669 } else if ((newcol - oldcol) == -2) {
670 // long un-castle
672 clearPiece(3);
673 }
674 }
675 } else {
676 // tSide::SIDE_BLACK
677 if (piece == tPiece::B_KING) {
678 m_boardInfo.s_boardInfo.blackKing = cf;
679 column_t oldcol = bCase::column(cf);
680 if ((newcol - oldcol) == 2) {
681 // short un-castle
683 clearPiece(61);
684 } else if ((newcol - oldcol) == -2) {
685 // long un-castle
687 clearPiece(59);
688 }
689 }
690 }
691 }
692 // set ply, kingpos, captured piece, castle flags, ...
693 m_boardInfo.u_boardInfo = oldBoardInfo.u_boardInfo;
694}
695
696//-----------------------------------------------------------------------
697
698std::string bBasicBoard::getHashStr() const
699{
700 std::stringstream ss;
701 ss << std::nouppercase << std::setfill('0')
702 << std::setw(16) << std::hex << m_hash;
703 return ss.str();
704}
705
706//-----------------------------------------------------------------------
707
708// eof
union boardInfo boardInfo_t
@ BCASTLE_L
Definition basicboard.h:14
@ BCASTLE_S
Definition basicboard.h:14
@ WCASTLE_S
Definition basicboard.h:14
@ WCASTLE_L
Definition basicboard.h:14
hashkey_t hashmultiplexer[tPiece::P_SIZE][64]
Definition bel_hash.cpp:10
constexpr hashkey_t HASH_INIT
Definition bel_hash.h:14
constexpr hashkey_t HASH_ODDMATERIAL
Definition bel_hash.h:16
uint64_t hashkey_t
Definition bel_hash.h:12
@ HP_CASTLE_FL
Definition bel_hash.h:19
constexpr hashkey_t HASH_BLACKTOMOVE
Definition bel_hash.h:15
This is the main include file, needs to be included before any other include.
int8_t rank_t
Definition belofte.h:94
uint8_t movenum50_t
Definition belofte.h:101
int8_t column_t
Definition belofte.h:95
uint8_t case_t
Definition belofte.h:96
uint16_t plynum_t
Definition belofte.h:99
constexpr piece_t getPiece(case_t const cf) const
Definition basicboard.h:172
void setCapturedPiece(piece_t p)
Definition basicboard.h:148
bFen getFEN() const
void incPieceCount()
Definition basicboard.h:263
void incPly()
Definition basicboard.h:80
void moveBlackKing(case_t const cf, case_t const ct)
constexpr int16_t getMoveNumber() const
Definition basicboard.h:160
boardInfo_t makeBoardMove(column_t const oldcol, rank_t const oldrank, column_t const newcol, rank_t const newrank)
apply move to check if in check only, board to be discarded as it will be in incomplete state,...
void movePiece(case_t const cf, case_t const ct, piece_t const np)
void restorePiece(case_t const cf, piece_t const op)
void setPly50Moves(movenum50_t const p)
Definition basicboard.h:105
boardInfo_t applyBlackMove(bMove const &m)
void incPly50Moves()
Definition basicboard.h:107
void moveWhiteKing(case_t const cf, case_t const ct)
constexpr bool hasCastleRights(uint8_t const f) const
Definition basicboard.h:113
boardInfo_t applyWhiteMove(bMove const &m)
void setEp(case_t const e)
set ep case, it will actually be stored as column only rank will be calculated based on side to move ...
void unApplyMove(bMove const &m, boardInfo_t const oldBoardInfo)
exact restoration of basic board using move details
void clearCapturedPiece()
Definition basicboard.h:152
std::string getHashStr() const
virtual boardInfo_t applyMove(bMove const &m)
play game move on board
void setNonSilent()
Definition basicboard.h:141
void decPieceCount()
Definition basicboard.h:265
constexpr case_t getEp() const
Definition basicboard.h:91
void setInCheck()
Definition basicboard.h:134
void unMakeBoardMove(case_t const &cf, column_t const newcol, rank_t const newrank, boardInfo_t const oldBoardInfo)
undo makeBoardMove, restoring previous situation
void capturePieceOn(piece_t const capturedPiece, case_t const ct)
Clear castle flag if rook captured update piece counter, update hash, clear field.
void clearPiece(case_t const cf)
Definition basicboard.h:199
void clearInCheck()
Definition basicboard.h:136
piece_t setGetPiece(column_t const newcol, rank_t const newrank, piece_t const piece)
Definition basicboard.h:186
piece_t removePiece(column_t const newcol, rank_t const newrank)
Definition basicboard.h:193
void swapPiece(case_t const cf, piece_t const op, piece_t const np)
constexpr movenum50_t getPly50Moves() const
Definition basicboard.h:103
constexpr bool isEpSet() const
Definition basicboard.h:89
constexpr int8_t pieceCount() const
Definition basicboard.h:221
void clearCastleRights(uint8_t const f)
constexpr side_t getColourToMove() const
Definition basicboard.h:162
void setBlackHasCastled()
Definition basicboard.h:117
void clearPly50Moves()
Definition basicboard.h:109
void calcHash()
Set hash based on board position, also calc pieces Byte 0: bits 4-6 capture count (masked) bit 7 play...
void setPieceCount(int8_t const n)
Definition basicboard.h:261
void setCastleRights(uint8_t const f)
void setWhiteHasCastled()
Definition basicboard.h:115
void setPieceKU(case_t const cf, piece_t const piece)
Definition basicboard.h:253
void setPiece(case_t const cf, piece_t const piece)
Definition basicboard.h:182
void setPly(plynum_t const p)
Definition basicboard.h:78
constexpr piece_t getCapturedPiece() const
Definition basicboard.h:146
constexpr bool isLongCastleMove() const
Definition basicmove.h:107
piece_t getWhitePromotionPiece() const
Definition basicmove.cpp:19
constexpr rank_t fromrank() const
Definition basicmove.h:61
piece_t getBlackPromotionPiece() const
Definition basicmove.cpp:33
constexpr bool isCastleMove() const
Definition basicmove.h:101
constexpr column_t tocolumn() const
Definition basicmove.h:67
constexpr bool isEPPossible() const
Definition basicmove.h:120
constexpr bool isCapture() const
Definition basicmove.h:93
constexpr case_t to() const
Definition basicmove.h:58
constexpr bool isPromotion() const
Definition basicmove.h:82
constexpr bool isEPMove() const
Definition basicmove.h:126
constexpr bool isCheck() const
Definition basicmove.h:109
constexpr case_t from() const
Definition basicmove.h:56
position on board, defined as 255 if invalid used primarily to compose a move or a source or destinat...
Definition case.h:18
constexpr column_t column() const
Definition case.h:41
static constexpr case_t coordToCase(column_t const c, rank_t const r)
Definition case.h:51
FEN string.
Definition fen.h:14
Definition move.h:13
static cpiece_t getPieceChar(piece_t const piece)
static class member function
Definition piece.cpp:219
constexpr piece_t getPiece() const
Definition piece.h:101
std::string alltrim(std::string s, std::string const &delim=" ")
trim left and right spaces or delim from string
Definition util.cpp:195
std::string to_string(int16_t value)
std::to_string not compatible on Mac OS (Apple LLVM version 5.0) provide generic utility function
Definition util.cpp:171
stringList const stringSplit(std::string src, std::string const &delim)
Split delimited long string into a vector.
Definition util.cpp:133
std::vector< std::string > stringList
Definition util.h:46
@ W_PAWN
Definition piece.h:39
@ P_SIZE
Definition piece.h:41
@ W_ROOK
Definition piece.h:39
@ B_ROOK
Definition piece.h:40
@ B_KING
Definition piece.h:40
@ P_EMPTY
Definition piece.h:38
@ W_KING
Definition piece.h:39
@ B_PAWN
Definition piece.h:40
enum tPiece piece_t
Definition piece.h:44
enum tCPiece cpiece_t
Definition piece.h:35
@ SIDE_BLACK
Definition piece.h:62
@ SIDE_WHITE
Definition piece.h:61
uint64_t u_boardInfo
Definition basicboard.h:20
struct boardInfo::@022254060033317030245227153321374007124317132060 s_boardInfo
uint8_t capturedpiece
4 castling bits, plus incheck flag and capture move
Definition basicboard.h:42
void setCapturedPiece(piece_t p)
Definition basicboard.h:22