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 
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;
37  : public ComputerPlayer,
39  {
40  public:
41  struct NtesukiThread;
42  struct Config
43  {
44  int limit;
45  size_t node_limit;
46  size_t table_size;
51  int verbose;
55  double draw_coef;
56  bool save_pv;
60  vector<boost::shared_ptr<search::SearchMonitor> > monitors;
61 
62  Config();
63  friend bool operator==(const Config& l, const Config& r);
64  };
65  protected:
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
76  boost::scoped_ptr<PVHistory> pv_history;
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  {
93  }
94  void enableSavePV(bool enable=true) { config.save_pv = enable; }
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;
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: