Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
search_perft.cpp
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: search_perft.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
16
20
22{
23 try {
24 if (getLevel()->getSearchDepth() == 0) {
25 m_nodes = 1LL; // by definition
26 } else {
27 CalcBestMove(b, getLevel()->getSearchDepth());
28 }
29 } catch (...) { throw; // push other exceptions down
30 }
31 return SCORE_UNDEFINED;
32}
33
34/** Do calculate # nodes from current position
35 * @param b position
36 * @param nDepth search for depth x, decreasing !!!
37 */
38void SearchPerft::CalcBestMove(bBoard& b, depth_t const nDepth)
39{
40 bMoveList ml(b);
41
42 movenum_t n_moves = ml.getNumberOfMoves();
43 if (nDepth > 1) {
44 for (movenum_t moveid = 1; moveid <= n_moves; moveid++) {
45 bMove m(ml[moveid]);
46 bBoard newboard(b, const_cast<bMove const&>(m));
47 CalcBestMove(newboard, nDepth - 1);
48 }
49 m_nonleafnodes += n_moves;
50 } else {
51 m_nodes += n_moves;
52 }
53}
54
55//-----------------------------------------------------------------------
56
57// eof
This is the main include file, needs to be included before any other include.
uint_fast8_t movenum_t
Definition belofte.h:109
int_fast8_t depth_t
Definition belofte.h:112
int16_t bScore
bScore CalcBestMove(bBoard &b) override
~SearchPerft() override
board
Definition board.h:147
Definition move.h:69
bLevel * getLevel()
Definition search.h:117
int64_t m_nonleafnodes
Definition search.h:108
int64_t m_nodes
Definition search.h:107
constexpr bScore SCORE_UNDEFINED
Definition eval.h:20