searchPlayer.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
searchPlayer.h
Go to the documentation of this file.
1 #ifndef GAME_PLAYING_SEARCHPLAYER_H
2 #define GAME_PLAYING_SEARCHPLAYER_H
3
4 #include "osl/game_playing/computerPlayer.h"
5 #include "osl/search/searchTimer.h"
6 #include "osl/misc/milliSeconds.h"
7 #include "osl/container/moveVector.h"
8 #include <boost/scoped_ptr.hpp>
9 #include <boost/shared_ptr.hpp>
10
11 namespace osl
12 {
13 namespace misc
14 {
15 class RealTime;
16 }
17 namespace search
18 {
19 class CountRecorder;
20 class SimpleHashTable;
21 struct TimeAssigned;
22 class SearchMonitor;
23 }
24 namespace checkmate
25 {
26 class DualDfpn;
27 }
28 namespace game_playing
29 {
30 struct Config;
31 bool operator==(const Config& l, const Config& r);
32 struct PVHistory;
36 class SearchPlayer
37 : public ComputerPlayer,
38 public ComputerPlayerSelectBestMoveInTime
39 {
40 public:
41 struct NtesukiThread;
42 struct Config
43 {
44 int limit;
45 size_t node_limit;
46 size_t table_size;
47 int table_record_limit;
48 int initial_limit;
49 int deepening_step;
50 size_t total_checkmate_limit;
51 int verbose;
53 double next_iteration_coefficient;
55 double draw_coef;
56 bool save_pv;
57 uint64_t node_count_hard_limit;
59 int multi_pv_width;
60 vector<boost::shared_ptr<search::SearchMonitor> > monitors;
61
62 Config();
63 friend bool operator==(const Config& l, const Config& r);
64 };
65 protected:
66 Config config;
67 boost::shared_ptr<search::SimpleHashTable> table_ptr;
68 boost::shared_ptr<checkmate::DualDfpn> checkmate_ptr;
69 boost::scoped_ptr<search::CountRecorder> recorder_ptr;
70 volatile bool searching;
71 boost::scoped_ptr<search::SearchTimer> searcher;
73 volatile bool plan_stop;
74 const MoveVector *root_ignore_moves; // acquaintance
75 bool prediction_for_speculative_search;
76 boost::scoped_ptr<PVHistory> pv_history;
77 int almost_resign_count;
78 public:
79 SearchPlayer();
80 SearchPlayer(const SearchPlayer&);
81 ~SearchPlayer();
82
83 void setDepthLimit(int limit, int initial_limit, int deepening_step);
84 void setNodeLimit(size_t node_limit);
85 void setNodeCountHardLimit(size_t node_limit);
86 void setTableLimit(size_t size, int record_limit);
87 void setVerbose(int verbose=1);
88 void setDrawCoef(double new_value) { config.draw_coef = new_value; }
89 void setNextIterationCoefficient(double new_value);
90 double nextIterationCoefficient() const
91 {
92 return config.next_iteration_coefficient;
93 }
94 void enableSavePV(bool enable=true) { config.save_pv = enable; }
95 void enableMultiPV(int width) { config.multi_pv_width = width; }
96 void addMonitor(const boost::shared_ptr<search::SearchMonitor>&);
97
99 void resetRecorder(search::CountRecorder *new_recorder);
100
101 void pushMove(Move m);
102 void popMove();
103
107 void swapTable(SearchPlayer& other);
108
109 const search::SimpleHashTable* table() const { return table_ptr.get(); }
110 const search::CountRecorder& recorder() const { return *recorder_ptr; }
111
112 bool stopSearchNow();
113 bool canStopSearch(); // 呼出を省略されないよう念の為 const でなくした
117 const MoveWithComment selectBestMove(const GameState&, int limit, int elapsed,
118 int byoyomi);
119 const MoveWithComment selectBestMoveInTime(const GameState&, const search::TimeAssigned&);
120 static const search::TimeAssigned assignTime(const GameState& state, int limit, int elapsed,
121 int byoyomi, int verbose);
122 const search::TimeAssigned assignTime(const GameState& state, int limit, int elapsed,
123 int byoyomi) const;
124 void saveSearchResult(const GameState&, const MoveWithComment&);
125 protected:
126 template <class Searcher>
127 ComputerPlayer* cloneIt(const Searcher&) const;
129 const MilliSeconds::Interval setUpTable(const GameState&, int pawn_value);
130 template <class Searcher>
131 const MoveWithComment search(const GameState&, const search::TimeAssigned&);
132 template <class Searcher>
133 bool isReasonableMoveBySearch(Searcher&, Move move, int pawn_sacrifice);
134 template <class Searcher>
135 static int pawnValue();
136 template <class Searcher>
137 static int pawnValueOfTurn(Player turn);
138 const search::TimeAssigned adjust(const search::TimeAssigned& org, const MilliSeconds::Interval& elapsed);
139 public:
140 virtual const MoveWithComment searchWithSecondsForThisMove(const GameState&, const search::TimeAssigned&)=0;
141 void setRootIgnoreMoves(const MoveVector *rim, bool prediction)
142 {
143 root_ignore_moves = rim;
144 prediction_for_speculative_search = prediction;
145 }
146
147 const Config& getConfig() const { return config; }
148
149 static int secondsForThisMove(const GameState& state,
150 int limit, int elapsed, int byoyomi, int verboseness);
151 int secondsForThisMove(const GameState& state, int limit, int elapsed, int byoyomi) const;
152
153 void setTimeAssign(const search::TimeAssigned& new_assign);
154 const MilliSeconds startTime() const;
155 };
156
157 } // namespace game_playing
158 } // namespace osl
159
160 #endif /* GAME_PLAYING_SEARCHPLAYER_H */
161 // ;;; Local Variables:
162 // ;;; mode:c++
163 // ;;; c-basic-offset:2
164 // ;;; End: