Go to the documentation of this file.00001
00002
00003 #include "osl/search/searchState2.h"
00004 #include "osl/search/simpleHashRecord.h"
00005 #include "osl/search/sacrificeCheck.h"
00006 #include "osl/record/csa.h"
00007 #include "osl/misc/milliSeconds.h"
00008 #include <iostream>
00009
00010
00011 osl::search::
00012 RecordStack2::RecordStack2()
00013 {
00014 clear();
00015 }
00016
00017 void osl::search::
00018 RecordStack2::clear()
00019 {
00020 data.clear();
00021 data.push_back(0);
00022 }
00023
00024 #ifndef MINIMAL
00025 void osl::search::
00026 RecordStack2::dump() const
00027 {
00028 std::cerr << "RecordStack\n";
00029 for (size_t i=0; i<data.size(); ++i) {
00030 std::cerr << data[i];
00031 std::cerr << std::endl;
00032 }
00033 }
00034 #endif
00035
00036
00037 osl::search::
00038 SearchState2Shared::SearchState2Shared()
00039 {
00040 }
00041
00042 osl::search::
00043 SearchState2Shared::~SearchState2Shared()
00044 {
00045 }
00046
00047
00048 #ifndef MINIMAL
00049 osl::CArray<int, osl::search::SearchState2Core::MaxDepth>
00050 osl::search::SearchState2Core::depth_node_count_quiesce;
00051 #endif
00052
00053 osl::search::
00054 SearchState2Core::SearchState2Core(const NumEffectState& s, checkmate_t& c)
00055 : current_state(s), checkmate_searcher(&c),
00056 current_path(s.turn()), root_depth(0),
00057 stop_tree(false)
00058 {
00059 setState(s);
00060 assert(hasLastRecord());
00061 }
00062 osl::search::
00063 SearchState2Core::~SearchState2Core()
00064 {
00065 }
00066
00067 void osl::search::
00068 SearchState2Core::setState(const NumEffectState& s)
00069 {
00070 if (&root_state != &s)
00071 root_state = s;
00072 restoreRootState();
00073 try
00074 {
00075 shared.reset();
00076 shared.reset(new SearchState2Shared());
00077 }
00078 catch (std::bad_alloc&)
00079 {
00080 std::cerr << "panic. allocation of SearchState2Shared failed\n";
00081 }
00082 }
00083
00084 void osl::search::
00085 SearchState2Core::restoreRootState()
00086 {
00087 current_state = root_state;
00088 current_path = PathEncoding(current_state.turn(), move_history.size());
00089 repetition_counter.clear();
00090 const HashKey key(current_state);
00091 repetition_counter.push(key, current_state);
00092 move_history.clear();
00093 record_stack.clear();
00094 root_depth = 0;
00095 }
00096
00097 void osl::search::
00098 SearchState2Core::setHistory(const MoveStack& h)
00099 {
00100 move_history = h;
00101 current_path = PathEncoding(current_path.turn(), h.size());
00102 root_depth = history().size();
00103 }
00104
00105 void osl::search::
00106 SearchState2Core::setBigramKillerMove(const BigramKillerMove& killers)
00107 {
00108 try
00109 {
00110 shared.reset();
00111 shared.reset(new SearchState2Shared());
00112 }
00113 catch (std::bad_alloc&)
00114 {
00115 std::cerr << "panic. allocation of SearchState2Shared failed\n";
00116 }
00117 shared->bigram_killers = killers;
00118 }
00119
00120 bool osl::search::
00121 SearchState2Core::abort() const
00122 {
00123 return abort(Move());
00124 }
00125
00126 bool osl::search::
00127 SearchState2Core::abort(Move best_move) const
00128 {
00129 std::cerr << state();
00130 #ifndef MINIMAL
00131 history().dump();
00132 const SimpleHashRecord *record = record_stack.lastRecord();
00133 std::cerr << "best move " << record::csa::show(best_move)
00134 << "\n";
00135 std::cerr << "record " << record << "\n";
00136 if (record)
00137 {
00138 record->dump(std::cerr);
00139 }
00140 record_stack.dump();
00141 repetition_counter.history().dump();
00142 #endif
00143 return false;
00144 }
00145
00146 void osl::search::SearchState2Core::makePV(PVVector& parent, Move m, PVVector& pv) const
00147 {
00148 parent.clear();
00149 parent.push_back(m);
00150 parent.push_back(pv.begin(), pv.end());
00151 #ifdef DEBUG_PV
00152 NumEffectState s = state();
00153 BOOST_FOREACH(Move p, parent) {
00154 if (! p.isPass() && ! s.isValidMove(p)) {
00155 std::cerr << "best move error " << p << " " << i << "\n";
00156 std::cerr << state();
00157 BOOST_FOREACH(Move q, parent)
00158 std::cerr << q << " ";
00159 std::cerr << "\n";
00160 ::abort();
00161 break;
00162 }
00163 ApplyMoveOfTurn::doMove(s, p);
00164 }
00165 #endif
00166 }
00167
00168 #ifndef NDEBUG
00169 void osl::search::
00170 SearchState2Core::makeMoveHook(Move)
00171 {
00172
00173 }
00174 #endif
00175
00176
00177
00178 osl::search::
00179 SearchState2::SearchState2(const NumEffectState& s, checkmate_t& c)
00180 : SearchState2Core(s, c), root_limit(0), cur_limit(0)
00181 {
00182 }
00183
00184 osl::search::
00185 SearchState2::~SearchState2()
00186 {
00187 }
00188
00189 void osl::search::
00190 SearchState2::setState(const NumEffectState& s)
00191 {
00192 SearchState2Core::setState(s);
00193 root_limit = cur_limit = 0;
00194 }
00195
00196 int osl::search::
00197 SearchState2::countSacrificeCheck2(int history_max) const
00198 {
00199 return SacrificeCheck::count2(recordHistory(), history(), history_max);
00200 }
00201
00202 bool osl::search::
00203 SearchState2::abort(Move best_move) const
00204 {
00205 std::cerr << "cur limit " << cur_limit
00206 << " root limit " << root_limit << "\n";
00207 SearchState2Core::abort(best_move);
00208 return false;
00209 }
00210
00211 void osl::search::
00212 SearchState2::checkPointSearchAllMoves()
00213 {
00214
00215 }
00216
00217
00218
00219
00220
00221