Belofte version 2.1.9
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
12/**
13 * Root search for algorithm
14 * @param b board
15 * @param ml movelist of this position
16 */
18{
19 depth_t nDepth = 1;
22 bScore terminalScore = RetrieveBoardEvaluation(b);
23
24 movenum_t n_moves = ml.getNumberOfMoves();
25 DEBUG_sendInfoSearching(b, nDepth, "PV InitialPosScore", terminalScore);
26
27 depth_t nNewDepth = nDepth + 1;
28 ml.clearScores();
29 for (movenum_t moveid = 1; moveid <= n_moves; ++moveid) {
30 bMove m(ml[moveid]);
31 sendInfoCurrMove(b, nDepth, m, moveid);
32 bBoard chldbrd(b, m);
33 b.applyMove(m);
35 bMoveList chldML;
36 bSearchScore chldscore(-Quiescence(chldbrd, chldML, -terminalScore, nNewDepth));
37 ml.setScoreOfMove(moveid, chldscore.getScore());
38 DEBUG_sendInfoSearching(b, nDepth, "PV MoveValue", chldscore.getScore());
39 }
40
41 return SCORE_UNDEFINED;
42}
43
44//-----------------------------------------------------------------------
45
46bScore SearchEvalPosOnly::Quiescence(bBoard& b,
47 bMoveList& ml, bScore nValueAtNullMove,
48 depth_t const nDepth)
49{
52
53 bScore terminalScore = RetrieveBoardEvaluation(b);
54
55 if (bSearchScore::realScore(terminalScore) > bSearchScore::realScore(nValueAtNullMove)) {
56 DEBUG_sendInfoSearching(b, nDepth, "st sc better than nullmove ("
57 + belofte::to_string(nValueAtNullMove)
58 + ") -- early cut off", terminalScore);
59 return terminalScore;
60 }
61
62 movenum_t n_moves = ml.generateMoves(b);
63 if (!ml.getNumberOfQSMoves()) {
64 /// @todo can be no moves position because of mate
65 DEBUG_sendInfoSearching(b, nDepth, "dead position (static eval)", terminalScore);
66 return terminalScore;
67 }
68
69 DEBUG_sendInfoSearching(b, nDepth, "(static eval)", terminalScore);
70
71 depth_t nNewDepth = nDepth + 1;
72 bSearchScore bestscore(terminalScore);
73 ml.clearScores();
74 for (movenum_t moveid = 1; moveid <= n_moves; ++moveid) {
75 bMove m(ml[moveid]);
76 if (m.isNonSilent() || m.isCheck()) {
77 sendInfoCurrMove(b, nDepth, m, moveid);
78 bBoard chldbrd(b, m);
79 chldbrd.applyMove(m);
81 bMoveList chldML;
82 bSearchScore chldscore(-Quiescence(chldbrd, chldML, -nValueAtNullMove, nNewDepth));
83 ml.setScoreOfMove(moveid, chldscore.getScore());
84 if (chldscore.improvesOn(bestscore)) {
85 b.setVariation(chldbrd);
86 bestscore = chldscore.getScore();
87 /// @todo first capture will always be better
88 if (chldscore.improvesOn(nValueAtNullMove)) {
89 DEBUG_sendInfoSearching(b, nDepth, "better than nullmove ("
90 + belofte::to_string(nValueAtNullMove)
91 + ") -- cut-off", chldscore.getScore());
92 return chldscore.getScore();
93 }
94 }
95 }
96 }
97
98 DEBUG_sendInfoSearching(b, nDepth, "(return best)", bestscore.getScore());
99 return bestscore.getScore();
100}
101
102//-----------------------------------------------------------------------
103
104// eof
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
Root search for algorithm.
board
Definition board.h:45
void setVariation(bBoard const &chldbrd)
Definition board.cpp:227
boardInfo_t applyMove(bMove const &m) override
modification of board move is kept on previous board newboard does not have move stored and has flag ...
Definition board.cpp:217
Definition move.h:13
void clearScores()
Definition movelist.h:52
movenum_t generateMoves(bBasicBoard const &b)
generate moves if not yet generated
Definition movelist.cpp:340
bool setScoreOfMove(movenum_t const moveid, bScore const score)
Store score of move and update best move.
Definition movelist.cpp:130
constexpr movenum_t getNumberOfMoves() const
Definition movelist.h:34
constexpr movenum_t getNumberOfQSMoves() const
Definition movelist.h:36
void adjustMaxSearchedDepth(depth_t const nDepth)
Definition search.h:132
void sendInfoCurrMove(bBoard const &b, depth_t const nCurDepth, bMove const &m, movenum_t const moveid) const
Definition search.cpp:223
int64_t m_nonleafnodes
Definition search.h:125
bScore RetrieveBoardEvaluation(bBoard &b, gameResult_t const gr=GR_UNSET) const
Get score of board, eventually from cache.
Definition search.cpp:242
void CheckIfAbortingSearch() const
Definition search.cpp:168
constexpr bScore realScore() const
Definition searchscore.h:66
constexpr bScore getScore() const
Definition searchscore.h:64
int16_t bScore
Definition eval.h:11
constexpr bScore SCORE_UNDEFINED
Definition eval.h:21
std::string to_string(int16_t value)
std::to_string not compatible on Mac OS (Apple LLVM version 5.0) provide generic utility function
Definition util.cpp:171
#define DEBUG_sendInfoSearching(b, depth, msg, sc)
Definition search.h:35