2011-11-12 20:44:06 +01:00
|
|
|
/*
|
|
|
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
|
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
2014-05-31 14:23:03 +02:00
|
|
|
Copyright (C) 2008-2014 Marco Costalba, Joona Kiiski, Tord Romstad
|
2011-11-12 20:44:06 +01:00
|
|
|
|
|
|
|
Stockfish is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Stockfish is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-08-20 20:02:33 +02:00
|
|
|
#ifndef SEARCH_H_INCLUDED
|
2011-11-12 20:44:06 +01:00
|
|
|
#define SEARCH_H_INCLUDED
|
|
|
|
|
2012-09-16 17:16:15 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <stack>
|
2012-01-01 01:52:19 +01:00
|
|
|
#include <vector>
|
2011-11-12 20:44:06 +01:00
|
|
|
|
2012-06-04 18:25:51 +02:00
|
|
|
#include "misc.h"
|
2012-09-16 17:16:15 +02:00
|
|
|
#include "position.h"
|
2011-11-12 20:44:06 +01:00
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
struct SplitPoint;
|
|
|
|
|
2012-01-01 01:52:19 +01:00
|
|
|
namespace Search {
|
2011-11-12 20:44:06 +01:00
|
|
|
|
2012-01-01 01:52:19 +01:00
|
|
|
/// The Stack struct keeps track of the information we need to remember from
|
|
|
|
/// nodes shallower and deeper in the tree during the search. Each search thread
|
|
|
|
/// has its own array of Stack objects, indexed by the current ply.
|
|
|
|
|
|
|
|
struct Stack {
|
2013-05-03 19:03:42 +02:00
|
|
|
SplitPoint* splitPoint;
|
2011-11-12 20:44:06 +01:00
|
|
|
int ply;
|
|
|
|
Move currentMove;
|
2014-05-31 14:23:03 +02:00
|
|
|
Move ttMove;
|
2011-11-12 20:44:06 +01:00
|
|
|
Move excludedMove;
|
|
|
|
Move killers[2];
|
|
|
|
Depth reduction;
|
2013-05-03 19:03:42 +02:00
|
|
|
Value staticEval;
|
2012-01-01 01:52:19 +01:00
|
|
|
int skipNullMove;
|
2011-11-12 20:44:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-15 02:13:33 +01:00
|
|
|
/// RootMove struct is used for moves at the root of the tree. For each root
|
|
|
|
/// move we store a score, a node count, and a PV (really a refutation in the
|
|
|
|
/// case of moves which fail low). Score is normally set at -VALUE_INFINITE for
|
|
|
|
/// all non-pv moves.
|
|
|
|
struct RootMove {
|
|
|
|
|
|
|
|
RootMove(Move m) : score(-VALUE_INFINITE), prevScore(-VALUE_INFINITE) {
|
|
|
|
pv.push_back(m); pv.push_back(MOVE_NONE);
|
|
|
|
}
|
|
|
|
|
2013-05-03 19:03:42 +02:00
|
|
|
bool operator<(const RootMove& m) const { return score > m.score; } // Ascending sort
|
2012-01-15 02:13:33 +01:00
|
|
|
bool operator==(const Move& m) const { return pv[0] == m; }
|
|
|
|
|
|
|
|
void extract_pv_from_tt(Position& pos);
|
|
|
|
void insert_pv_in_tt(Position& pos);
|
|
|
|
|
|
|
|
Value score;
|
|
|
|
Value prevScore;
|
|
|
|
std::vector<Move> pv;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-01 01:52:19 +01:00
|
|
|
/// The LimitsType struct stores information sent by GUI about available time
|
2011-11-12 20:44:06 +01:00
|
|
|
/// to search the current move, maximum depth/time, if we are in analysis mode
|
2014-05-31 14:23:03 +02:00
|
|
|
/// or if we have to ponder while it's our opponent's turn to move.
|
2011-11-12 20:44:06 +01:00
|
|
|
|
2012-01-01 01:52:19 +01:00
|
|
|
struct LimitsType {
|
2011-11-12 20:44:06 +01:00
|
|
|
|
2014-05-31 14:23:03 +02:00
|
|
|
LimitsType() { // Using memset on a std::vector is undefined behavior
|
|
|
|
time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = movestogo =
|
|
|
|
depth = nodes = movetime = mate = infinite = ponder = 0;
|
|
|
|
}
|
2013-05-03 19:03:42 +02:00
|
|
|
bool use_time_management() const { return !(mate | movetime | depth | nodes | infinite); }
|
2011-11-12 20:44:06 +01:00
|
|
|
|
2014-05-31 14:23:03 +02:00
|
|
|
std::vector<Move> searchmoves;
|
2013-05-03 19:03:42 +02:00
|
|
|
int time[COLOR_NB], inc[COLOR_NB], movestogo, depth, nodes, movetime, mate, infinite, ponder;
|
2012-01-01 01:52:19 +01:00
|
|
|
};
|
2011-11-12 20:44:06 +01:00
|
|
|
|
|
|
|
|
2012-01-01 01:52:19 +01:00
|
|
|
/// The SignalsType struct stores volatile flags updated during the search
|
2014-05-31 14:23:03 +02:00
|
|
|
/// typically in an async fashion e.g. to stop the search by the GUI.
|
2012-01-01 01:52:19 +01:00
|
|
|
|
|
|
|
struct SignalsType {
|
2014-05-31 14:23:03 +02:00
|
|
|
bool stop, stopOnPonderhit, firstRootMove, failedLowAtRoot;
|
2011-11-12 20:44:06 +01:00
|
|
|
};
|
|
|
|
|
2012-09-16 17:16:15 +02:00
|
|
|
typedef std::auto_ptr<std::stack<StateInfo> > StateStackPtr;
|
|
|
|
|
2012-01-01 01:52:19 +01:00
|
|
|
extern volatile SignalsType Signals;
|
|
|
|
extern LimitsType Limits;
|
2012-01-15 02:13:33 +01:00
|
|
|
extern std::vector<RootMove> RootMoves;
|
2013-05-03 19:03:42 +02:00
|
|
|
extern Position RootPos;
|
|
|
|
extern Color RootColor;
|
2012-09-16 17:16:15 +02:00
|
|
|
extern Time::point SearchTime;
|
|
|
|
extern StateStackPtr SetupStates;
|
2012-01-01 01:52:19 +01:00
|
|
|
|
|
|
|
extern void init();
|
2014-05-31 14:23:03 +02:00
|
|
|
extern uint64_t perft(Position& pos, Depth depth);
|
2012-01-01 01:52:19 +01:00
|
|
|
extern void think();
|
|
|
|
|
2012-01-15 02:13:33 +01:00
|
|
|
} // namespace Search
|
2011-11-12 20:44:06 +01:00
|
|
|
|
2013-08-20 20:02:33 +02:00
|
|
|
#endif // #ifndef SEARCH_H_INCLUDED
|