Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
search_bf.cpp
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: search_bf.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
19{
20}
21
25
27{
28 // TODO: search from depth till zero
29 return CalcBestMove(b, 0);
30}
31
32/**
33 * Actual search, recursively callable
34 * @param b board
35 * @param nDepth remaining depth to search on
36 * @return SCORE_UNDEFINED | [-]SCORE_INFINITE | actual score
37 */
39{
40 if (nDepth > m_maxDepth) m_maxDepth = nDepth;
41#if defined(_DEBUG)
42 std::string izing = std::string(b.minimizing() > 0 ? "White" : "Black") + " to move";
43#endif // defined
44
45 if (getLevel()->searchDepthReached(nDepth)) {
46 m_nodes++;
47 return DEBUG_returnInfoSearching(b, nDepth, izing + " - Depth reached", RetrieveBoardEvaluation(b));
48 }
49 if (nDepth) m_nonleafnodes++;
50
53
54 bMoveList& ml = b.getMoveListRef();
55 movenum_t n_moves = ml.generateMoves(b);
56
57 if (!n_moves) {
58 return DEBUG_returnInfoSearching(b, nDepth, izing + " - Dead position", RetrieveBoardEvaluation(b));
59 } else {
60 DEBUG_sendInfoSearching(b, nDepth, izing + " - (static eval)", RetrieveBoardEvaluation(b));
61 for (movenum_t moveid = 1; moveid <= n_moves; moveid++) {
62#if defined(_DEBUG)
63 sendInfoCurrMove(b, nDepth, moveid);
64#endif // defined
65 bMove m = ml[moveid];
66 bBoard chldbrd(b, m);
67 bSearchScore chldscore(-CalcBestMove(chldbrd, nDepth + 1), tScoreType::SC_CHILD);
68 chldscore = attenuateScore(chldscore.getScore());
69 ml.setScoreOfMove(moveid, chldscore.getScore());
70 if (chldscore > bestscore) {
71 b.setVariation(chldbrd);
72 bestscore = chldscore.getScore();
73 }
74 }
75 }
76
77 return DEBUG_returnInfoSearching(b, nDepth, "(return best)", bestscore.getScore());
78}
79
80//-----------------------------------------------------------------------
81
83 : SearchBruteForce("IterativeBruteForce")
84{
85 m_iterativesearch = true;
86}
87
91
92// 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
~SearchBruteForce() override
Definition search_bf.cpp:22
bScore CalcBestMove(bBoard &b) override
Definition search_bf.cpp:26
~SearchIterativeBF() override
Definition search_bf.cpp:88
board
Definition board.h:147
void setVariation(bBoard const &chldbrd)
Definition board.cpp:979
bMoveList & getMoveListRef()
return reference to movelist
Definition board.cpp:954
bScore minimizing() const
Definition board.h:180
Definition move.h:69
movenum_t setScoreOfMove(movenum_t const moveid, bScore const score)
Store score of move.
Definition movelist.cpp:207
movenum_t generateMoves(bBoard const &b)
generate moves if not yet generated
Definition movelist.cpp:259
void sendInfoCurrMove(bBoard const &b, depth_t const nDepth, movenum_t const moveid) const
Definition search.cpp:327
bScore attenuateScore(bScore const sc) const
converge score towards zero in order to force immediate best move first
Definition search.cpp:356
depth_t m_maxDepth
Definition search.h:106
bScore RetrieveBoardEvaluation(bBoard &b) const
Cache score of board.
Definition search.cpp:343
bool m_iterativesearch
Definition search.h:109
bLevel * getLevel()
Definition search.h:117
int64_t m_nonleafnodes
Definition search.h:108
int64_t m_nodes
Definition search.h:107
void CheckIfAbortingSearch() const
Definition search.cpp:278
constexpr bScore SCORE_INFINITE
Definition eval.h:15
#define DEBUG_returnInfoSearching(b, depth, msg, sc)
Definition search.h:32
@ SC_BEST
Definition search.h:40
@ SC_CHILD
Definition search.h:40
#define DEBUG_sendInfoSearching(b, depth, msg, sc)
Definition search.h:31