All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
searchState2.cc
Go to the documentation of this file.
1 /* searchState2.cc
2  */
6 #include "osl/record/csa.h"
8 #include <iostream>
9 
10 /* ------------------------------------------------------------------------- */
13 {
14  clear();
15 }
16 
17 void osl::search::
19 {
20  data.clear();
21  data.push_back(0);
22 }
23 
24 #ifndef MINIMAL
25 void osl::search::
27 {
28  std::cerr << "RecordStack\n";
29  for (size_t i=0; i<data.size(); ++i) {
30  std::cerr << data[i];
31  std::cerr << std::endl;
32  }
33 }
34 #endif
35 /* ------------------------------------------------------------------------- */
36 
39 {
40 }
41 
44 {
45 }
46 
47 
48 #ifndef MINIMAL
49 osl::CArray<int, osl::search::SearchState2Core::MaxDepth>
51 #endif
52 
54 SearchState2Core::SearchState2Core(const NumEffectState& s, checkmate_t& c)
55  : current_state(s), checkmate_searcher(&c),
56  current_path(s.turn()), root_depth(0),
57  stop_tree(false)
58 {
59  setState(s); // initialize shared
60  assert(hasLastRecord());
61 }
64 {
65 }
66 
67 void osl::search::
68 SearchState2Core::setState(const NumEffectState& s)
69 {
70  if (&root_state != &s)
71  root_state = s;
72  restoreRootState();
73  try
74  {
75  shared.reset();
76  shared.reset(new SearchState2Shared());
77  }
78  catch (std::bad_alloc&)
79  {
80  std::cerr << "panic. allocation of SearchState2Shared failed\n";
81  }
82 }
83 
84 void osl::search::
86 {
87  current_state = root_state;
88  current_path = PathEncoding(current_state.turn(), move_history.size());
89  repetition_counter.clear();
90  const HashKey key(current_state);
91  repetition_counter.push(key, current_state);
92  move_history.clear();
93  record_stack.clear();
94  root_depth = 0;
95 }
96 
97 void osl::search::
98 SearchState2Core::setHistory(const MoveStack& h)
99 {
100  move_history = h;
101  current_path = PathEncoding(current_path.turn(), h.size());
102  root_depth = history().size();
103 }
104 
105 void osl::search::
107 {
108  try
109  {
110  shared.reset();
111  shared.reset(new SearchState2Shared());
112  }
113  catch (std::bad_alloc&)
114  {
115  std::cerr << "panic. allocation of SearchState2Shared failed\n";
116  }
117  shared->bigram_killers = killers;
118 }
119 
120 bool osl::search::
122 {
123  return abort(Move());
124 }
125 
126 bool osl::search::
128 {
129  std::cerr << state();
130 #ifndef MINIMAL
131  history().dump();
132  const SimpleHashRecord *record = record_stack.lastRecord();
133  std::cerr << "best move " << record::csa::show(best_move)
134  << "\n";
135  std::cerr << "record " << record << "\n";
136  if (record)
137  {
138  record->dump(std::cerr);
139  }
140  record_stack.dump();
141  repetition_counter.history().dump();
142 #endif
143  return false;
144 }
145 
147 {
148  parent.clear();
149  parent.push_back(m);
150  parent.push_back(pv.begin(), pv.end());
151 #ifdef DEBUG_PV
152  NumEffectState s = state();
153  BOOST_FOREACH(Move p, parent) {
154  if (! p.isPass() && ! s.isValidMove(p)) {
155  std::cerr << "best move error " << p << " " << i << "\n";
156  std::cerr << state();
157  BOOST_FOREACH(Move q, parent)
158  std::cerr << q << " ";
159  std::cerr << "\n";
160  ::abort();
161  break;
162  }
163  ApplyMoveOfTurn::doMove(s, p);
164  }
165 #endif
166 }
167 
168 #ifndef NDEBUG
169 void osl::search::
171 {
172  // history().dump();
173 }
174 #endif
175 
176 /* ------------------------------------------------------------------------- */
177 
179 SearchState2::SearchState2(const NumEffectState& s, checkmate_t& c)
180  : SearchState2Core(s, c), root_limit(0), cur_limit(0)
181 {
182 }
183 
186 {
187 }
188 
189 void osl::search::
190 SearchState2::setState(const NumEffectState& s)
191 {
193  root_limit = cur_limit = 0;
194 }
195 
196 int osl::search::
198 {
199  return SacrificeCheck::count2(recordHistory(), history(), history_max);
200 }
201 
202 bool osl::search::
203 SearchState2::abort(Move best_move) const
204 {
205  std::cerr << "cur limit " << cur_limit
206  << " root limit " << root_limit << "\n";
207  SearchState2Core::abort(best_move);
208  return false;
209 }
210 
211 void osl::search::
213 {
214  // debug code can be written here
215 }
216 
217 /* ------------------------------------------------------------------------- */
218 // ;;; Local Variables:
219 // ;;; mode:c++
220 // ;;; c-basic-offset:2
221 // ;;; End: