Belofte  version 2.1.5
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 
13  : bSearchAlgorithm("Perft")
14 {
15 }
16 
18 {
19 }
20 
22 {
23  bBestMoveInfo result;
24  try {
25  if (getLevel()->getDepth() == 0) {
26  m_leafnodes = 1LL; // by definition
27  } else {
28  DoSearchPerft(b, getLevel()->getDepth());
29  }
30  } catch (...) { throw; // push other exceptions down
31  }
32  return result;
33 }
34 
35 /** Do calculate # nodes from current position
36  * @param b position
37  * @param nDepth search for depth x, decreasing !!!
38  */
39 void SearchPerft::DoSearchPerft(bBoard const& b, depth_t const& nDepth)
40 {
41  bMoveList ml(b);
42 
43  if (nDepth > 1) {
44  movenum_t n_moves = ml.getNumberOfMoves();
45  for (movenum_t moveid = 1; moveid <= n_moves; moveid++) {
46  bBoard newboard(b, ml[moveid]);
47  DoSearchPerft(newboard, nDepth - 1);
48  }
49  m_nonleafnodes += n_moves;
50  } else {
51  m_leafnodes += ml.getNumberOfMoves();
52  }
53 }
54 
55 //-----------------------------------------------------------------------
56 
57 // eof
This is the main include file, needs to be included before any other include.
uint_fast16_t movenum_t
moveflags (high order word) & basicmove (low order word)
Definition: belofte.h:103
int_fast8_t depth_t
Definition: belofte.h:105
bBestMoveInfo CalcBestMove(bBoard &b) override
~SearchPerft() override
board
Definition: board.h:111
bLevel * getLevel()
Definition: search.h:66
int64_t m_nonleafnodes
Definition: search.h:58
int64_t m_leafnodes
Definition: search.h:57