Belofte version 2.1.8
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
16
20
22{
23 m_maxDepth = 1;
24 bScore boardscore = RetrieveBoardEvaluation(b);
25
26 bMoveList& ml = b.getMoveListRef();
27 movenum_t n_moves = ml.getNumberOfMoves();
28 DEBUG_sendInfoSearching(b, 0, "PV InitialPosScore", boardscore);
29
30 for (movenum_t moveid = 1; moveid <= n_moves; moveid++) {
32 sendInfoCurrMove(b, 1, moveid);
33 bBoard chldbrd(b, moveid);
35 bSearchScore chldscore(-Quiescence(chldbrd, -boardscore, 2), tScoreType::SC_CHILD);
36 ml.setScoreOfMove(moveid, chldscore.getScore());
37 DEBUG_sendInfoSearching(b, 0, "PV MoveValue", chldscore.getScore());
38 }
39
40 return SCORE_UNDEFINED;
41}
42
43//-----------------------------------------------------------------------
44
45bScore SearchEvalPosOnly::Quiescence(bBoard& b, bScore nValueAtNullMove,
46 depth_t const nDepth)
47{
48 if (nDepth > m_maxDepth) m_maxDepth = nDepth;
49 bScore boardscore = RetrieveBoardEvaluation(b);
50
51#if defined(_DEBUG)
52 std::string izing = std::string(b.minimizing() > 0 ? "White" : "Black") + " to move";
53#endif
54
55 if (belofte::realScore(boardscore) > belofte::realScore(nValueAtNullMove)) {
56 return DEBUG_returnInfoSearching(b, nDepth, izing + " st sc better than nullmove ("
57 + belofte::to_string(nValueAtNullMove)
58 + ") -- early cut off", boardscore);
59 }
60
61 bMoveList& ml = b.getMoveListRef();
62 movenum_t n_moves = ml.generateMoves(b);
63 if (!ml.getNumberOfQSMoves()) {
64 // TODO: can be no moves position because of mate
65 return DEBUG_returnInfoSearching(b, nDepth, "dead position (static eval)",
66 boardscore);
67 }
68
69 DEBUG_sendInfoSearching(b, nDepth, izing + " (static eval)", boardscore);
70
71 bSearchScore bestscore(boardscore, tScoreType::SC_BEST);
72 for (movenum_t moveid = 1; moveid <= n_moves; moveid++) {
73 if (ml[moveid].isNonSilent() || ml[moveid].isCheck()) {
75 sendInfoCurrMove(b, nDepth, moveid);
76 bBoard chldbrd(b, moveid);
78 bSearchScore chldscore(-Quiescence(chldbrd, -nValueAtNullMove, nDepth + 1), tScoreType::SC_CHILD);
79 ml.setScoreOfMove(moveid, chldscore.getScore());
80 if (chldscore > bestscore) {
81 b.setVariation(chldbrd);
82 bestscore = chldscore.getScore();
83 // TODO: first capture will always be better
84 if (chldscore > belofte::realScore(nValueAtNullMove)) {
85 return DEBUG_returnInfoSearching(b, nDepth, "better than nullmove ("
86 + belofte::to_string(nValueAtNullMove)
87 + ") -- cut-off", chldscore.getScore());
88 }
89 }
90 }
91 }
92
93 return DEBUG_returnInfoSearching(b, nDepth, "(return best)", bestscore.getScore());
94}
95
96//-----------------------------------------------------------------------
97
98// 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
~SearchEvalPosOnly() override
bScore CalcBestMove(bBoard &b) override
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
movenum_t setScoreOfMove(movenum_t const moveid, bScore const score)
Store score of move.
Definition movelist.cpp:207
movenum_t getNumberOfQSMoves() const
return number of non silent moves
Definition movelist.cpp:339
movenum_t getNumberOfMoves() const
Definition movelist.cpp:332
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
depth_t m_maxDepth
Definition search.h:106
bScore RetrieveBoardEvaluation(bBoard &b) const
Cache score of board.
Definition search.cpp:343
int64_t m_nonleafnodes
Definition search.h:108
void CheckIfAbortingSearch() const
Definition search.cpp:278
bScore getScore() const
Definition search.h:62
constexpr bScore SCORE_UNDEFINED
Definition eval.h:20
bScore realScore(bScore const sc)
Definition eval.cpp:23
#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