Belofte  version 2.1.5
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 
13  : bSearchAlgorithm("BruteForce")
14 {
15 }
16 
18  : bSearchAlgorithm(n)
19 {
20 }
21 
23 {
24 }
25 
27 {
28  // TODO: search from depth till zero
29  bBestMoveInfo result;
30  result = CalcBestMove(b, 0);
31  return result;
32 }
33 
34 /**
35  * Actual search, recursively callable
36  * @param b board
37  * @param nDepth remaining depth to search on
38  * @return SCORE_UNDEFINED | [-]SCORE_INFINITE | actual score
39  */
41 {
42  if (nDepth > m_maxDepth) m_maxDepth = nDepth;
43  std::string izing = std::string(b.minimizing() > 0 ? "White" : "Black") + " to move";
44  movenum_t n_moves = b.generateAtLeastOneMove();
45 
47  if (getLevel()->depthReached(nDepth)) {
48  ++m_leafnodes;
49  return sendInfoSearching(b, nDepth, izing + " - Depth reached", sc);
50  }
51  if (nDepth) ++m_nonleafnodes;
52 
54 
55  if (!n_moves) {
56  return sendInfoSearching(b, nDepth, izing + " - Dead position", sc);
57  } else {
58  sendInfoSearching(b, nDepth, izing + " - (static eval)", sc);
59  n_moves = b.generateMoves();
60  bMoveList& ml = b.getMoves();
61  for (movenum_t moveid = 1; moveid <= n_moves; moveid++) {
62  handleInfoCurrMove(b, ml, nDepth, moveid);
63  bBoard chldbrd(b, ml[moveid], ml.getMoveT(moveid));
64  bSearchScore chldscore(CalcBestMove(chldbrd, nDepth + 1), tScoreType::SC_CHILD);
65  chldscore = -attenuateScore(chldscore.getScore());
66  ml.updateScoreOfBestMove(moveid, chldscore.getScore());
67  if (chldscore > bestscore) {
68  b.setVariation(chldbrd);
69  bestscore = chldscore.getScore();
70  }
71  }
72  }
73 
74  return sendInfoSearching(b, nDepth, "(return best)", bestscore.getScore());
75 }
76 
77 //-----------------------------------------------------------------------
78 
80  : SearchBruteForce("SearchIterativeBF")
81 {
82  m_iterativesearch = true;
83 }
84 
86 {
87 }
88 
89 // 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_fast16_t bScore
used to return id of move in movelist
Definition: belofte.h:104
int_fast8_t depth_t
Definition: belofte.h:105
bBestMoveInfo CalcBestMove(bBoard &b) override
Definition: search_bf.cpp:26
~SearchBruteForce() override
Definition: search_bf.cpp:22
~SearchIterativeBF() override
Definition: search_bf.cpp:85
board
Definition: board.h:111
movenum_t generateMoves()
generate moves if not yet generated
Definition: board.cpp:710
void setVariation(bBoard const &chldbrd)
Definition: board.cpp:744
bMoveList & getMoves()
return moves in position, initialise structure if needed
Definition: board.cpp:731
bScore minimizing() const
Definition: board.h:149
movenum_t generateAtLeastOneMove()
see if at least one move can be played e.g.
Definition: board.cpp:718
movenum_t updateScoreOfBestMove(movenum_t const moveid, bScore const score)
Store score of move.
Definition: movelist.cpp:203
move_t getMoveT(movenum_t const moveid) const
Definition: movelist.cpp:391
bScore attenuateScore(bScore const sc) const
converge score towards zero in order to force immediate best move first
Definition: search.cpp:261
depth_t m_maxDepth
Definition: search.h:56
bScore RetrieveBoardEvaluation(bBoard &b) const
Cache score of board.
Definition: search.cpp:248
bool m_iterativesearch
Definition: search.h:59
bLevel * getLevel()
Definition: search.h:66
void handleInfoCurrMove(bBoard const &b, bMoveList const &ml, depth_t const &nDepth, movenum_t const moveid) const
Definition: search.cpp:232
int64_t m_nonleafnodes
Definition: search.h:58
bScore sendInfoSearching(bBoard const &b, depth_t const nDepth, std::string const &c, bScore const sc) const
Definition: search.cpp:191
int64_t m_leafnodes
Definition: search.h:57
constexpr bScore SCORE_INFINITE
Definition: eval.h:15
@ SC_BEST
Definition: searchscore.h:15
@ SC_CHILD
Definition: searchscore.h:15