Belofte  version 2.1.5
A promising chess program using the UCI or Winboard interface
search_qsonly.cpp
Go to the documentation of this file.
1 /*---------------------------------------------------------------------+
2  * File: search_qsonly.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("StaticEval")
14 {
15 }
16 
18 {
19 }
20 
22 {
23  bBestMoveInfo result;
24  m_maxDepth = 1;
25 
26  movenum_t n_moves = b.generateMoves();
27  bMoveList& ml = b.getMoves();
29  sendInfoSearching(b, 0, "PV InitialPosScore", sc);
30 
31  for (movenum_t moveid = 1; moveid <= n_moves; moveid++) {
32  handleInfoCurrMove(b, ml, 1, moveid);
33  bBoard chldbrd(b, ml[moveid], ml.getMoveT(moveid));
35  bScore chldscore = -Quiescence(chldbrd, -sc, 2);
36  ml.updateScoreOfBestMove(moveid, chldscore);
37  sendInfoSearching(b, 0, "PV MoveValue", chldscore);
38  }
39 
40  return result;
41 }
42 
43 //-----------------------------------------------------------------------
44 
45 bScore SearchEvalPosOnly::Quiescence(bBoard& b, bScore nValueAtNullMove,
46  depth_t const nDepth)
47 {
48  if (nDepth > m_maxDepth) m_maxDepth = nDepth;
50  bScore boardscore = RetrieveBoardEvaluation(b);
51 
52  std::string izing = std::string(b.minimizing() > 0 ? "White" : "Black") + " to move";
53 
54  if (belofte::realScore(boardscore) > belofte::realScore(nValueAtNullMove)) {
55  return sendInfoSearching(b, nDepth, izing + " st sc better than nullmove ("
56  + belofte::to_string(nValueAtNullMove)
57  + ") -- early cut off", boardscore);
58  }
59 
60  if (!b.generateAtLeastOneQSMove()) {
61  // TODO: can be no moves position because of mate
62  return sendInfoSearching(b, nDepth, "dead position (static eval)",
63  boardscore);
64  }
65 
66  sendInfoSearching(b, nDepth, izing + " (static eval)", boardscore);
67 
68  bSearchScore bestscore(boardscore, tScoreType::SC_BEST);
69 
70  movenum_t n_moves = b.generateMoves();
71  bMoveList& ml = b.getMoves();
72  for (movenum_t moveid = 1; moveid <= n_moves; moveid++) {
73  if (ml[moveid].isNonSilent() || ml[moveid].isCheck()) {
74  handleInfoCurrMove(b, ml, nDepth, moveid);
75  bBoard chldbrd(b, ml[moveid], ml.getMoveT(moveid));
77  bScore chldscore = -Quiescence(chldbrd, -nValueAtNullMove, nDepth + 1);
78  ml.updateScoreOfBestMove(moveid, chldscore);
79  if (chldscore > bestscore) {
80  b.setVariation(chldbrd);
81  bestscore = chldscore;
82  // TODO: first capture will always be better
83  if (chldscore > belofte::realScore(nValueAtNullMove)) {
84  return sendInfoSearching(b, nDepth, "better than nullmove ("
85  + belofte::to_string(nValueAtNullMove)
86  + ") -- cut-off", chldscore);
87  }
88  }
89  }
90  }
91 
92  return sendInfoSearching(b, nDepth, "(return best)", bestscore);
93 }
94 
95 //-----------------------------------------------------------------------
96 
97 // 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
~SearchEvalPosOnly() override
bBestMoveInfo CalcBestMove(bBoard &b) override
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 generateAtLeastOneQSMove()
Definition: board.cpp:723
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
depth_t m_maxDepth
Definition: search.h:56
bScore RetrieveBoardEvaluation(bBoard &b) const
Cache score of board.
Definition: search.cpp:248
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
bScore realScore(bScore const sc)
Definition: eval.cpp:23
std::string to_string(long value)
std::to_string not compatible on Mac OS (Apple LLVM version 5.0) provide generic utility function
Definition: util.cpp:168
@ SC_BEST
Definition: searchscore.h:15