Belofte version 2.1.9
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
12#if defined(__GNUC__)
13#pragma GCC diagnostic push
14#pragma GCC diagnostic ignored "-Wunused-parameter"
15#endif
16
17/**
18 * Entry point for SearchPerft
19 * @param b position
20 * @param ml movelist of this position
21 */
23{
24 depth_t nDepth = getLevel()->getSearchDepth();
25 try {
26 if (!nDepth) {
27 m_leafnodes = 1LL; // by definition
28 } else {
29 bBasicBoard newboard(b);
30 CalcBestMove(newboard, nDepth);
31 }
32 } catch (...) { throw; // push other exceptions down
33 }
34 return SCORE_UNDEFINED;
35}
36
37#if defined(__GNUC__)
38#pragma GCC diagnostic pop
39#endif
40
41/**
42 * Do calculate # nodes from current position
43 * @param bb position
44 * @param nDepth search for depth x, decreasing !!!
45 */
47{
48 bMoveList ml;
49 ml.clearNeedSorted();
50 ml.clearKeepScores();
51
52 movenum_t n_moves = ml.generateMoves(bb);
53 if (nDepth > 1) {
54 --nDepth;
55 for (movenum_t moveid = 1; moveid <= n_moves; ++moveid) {
56 bMove m(ml[moveid]);
57 boardInfo_t bi = bb.applyMove(m);
58 CalcBestMove(bb, nDepth);
59 bb.unApplyMove(m, bi);
60 }
61 m_nonleafnodes += n_moves;
62 } else {
63 m_leafnodes += n_moves;
64 }
65}
66
67//-----------------------------------------------------------------------
68
69// eof
union boardInfo boardInfo_t
This is the main include file, needs to be included before any other include.
uint_fast8_t movenum_t
Definition belofte.h:100
int_fast8_t depth_t
Definition belofte.h:103
bScore CalcBestMove(bBoard &b, bMoveList &ml) override
Entry point for SearchPerft.
void unApplyMove(bMove const &m, boardInfo_t const oldBoardInfo)
exact restoration of basic board using move details
virtual boardInfo_t applyMove(bMove const &m)
play game move on board
board
Definition board.h:45
constexpr depth_t getSearchDepth() const
Definition level.h:98
Definition move.h:13
void clearNeedSorted()
Definition movelist.h:75
movenum_t generateMoves(bBasicBoard const &b)
generate moves if not yet generated
Definition movelist.cpp:340
void clearKeepScores()
Definition movelist.h:79
bLevel * getLevel()
Definition search.h:141
int64_t m_nonleafnodes
Definition search.h:125
int64_t m_leafnodes
Definition search.h:124
int16_t bScore
Definition eval.h:11
constexpr bScore SCORE_UNDEFINED
Definition eval.h:21