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/realTime.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 void osl::search::
00025 RecordStack2::dump() const
00026 {
00027 std::cerr << "RecordStack\n";
00028 for (size_t i=0; i<data.size(); ++i) {
00029 std::cerr << data[i];
00030 std::cerr << std::endl;
00031 }
00032 }
00033
00034
00035
00036 osl::search::
00037 SearchState2Shared::SearchState2Shared()
00038 {
00039 }
00040
00041 osl::search::
00042 SearchState2Shared::~SearchState2Shared()
00043 {
00044 }
00045
00046
00047 osl::CArray<int, osl::search::SearchState2Core::MaxDepth>
00048 osl::search::SearchState2Core::depth_node_count_quiesce;
00049
00050 osl::search::
00051 SearchState2Core::SearchState2Core(const NumEffectState& s, checkmate_t& c)
00052 : current_state(s), checkmate_searcher(&c),
00053 current_path(s.getTurn()), root_depth(0),
00054 stop(false)
00055 {
00056 setState(s);
00057 assert(hasLastRecord());
00058 }
00059 osl::search::
00060 SearchState2Core::~SearchState2Core()
00061 {
00062 }
00063
00064 void osl::search::
00065 SearchState2Core::setState(const NumEffectState& s)
00066 {
00067 if (¤t_state != &s)
00068 current_state = s;
00069 current_path = PathEncoding(s.getTurn(), move_history.size());
00070 try
00071 {
00072 shared.reset();
00073 shared.reset(new SearchState2Shared());
00074 }
00075 catch (std::bad_alloc&)
00076 {
00077 std::cerr << "panic. allocation of SearchState2Shared failed\n";
00078 }
00079 repetition_counter.clear();
00080 const HashKey key = HashKey::calcHash(s);
00081 repetition_counter.push(key, s);
00082 move_history.clear();
00083 record_stack.clear();
00084 root_depth = 0;
00085 }
00086
00087 void osl::search::
00088 SearchState2Core::setHistory(const MoveStack& h)
00089 {
00090 move_history = h;
00091 current_path = PathEncoding(current_path.turn(), h.size());
00092 root_depth = history().size();
00093 }
00094
00095 void osl::search::
00096 SearchState2Core::setBigramKillerMove(const BigramKillerMove& killers)
00097 {
00098 try
00099 {
00100 shared.reset();
00101 shared.reset(new SearchState2Shared());
00102 }
00103 catch (std::bad_alloc&)
00104 {
00105 std::cerr << "panic. allocation of SearchState2Shared failed\n";
00106 }
00107 shared->bigram_killers = killers;
00108 }
00109
00110 bool osl::search::
00111 SearchState2Core::abort() const
00112 {
00113 return abort(Move());
00114 }
00115
00116 bool osl::search::
00117 SearchState2Core::abort(Move best_move) const
00118 {
00119 std::cerr << state();
00120 history().dump();
00121 const SimpleHashRecord *record = record_stack.lastRecord();
00122 std::cerr << "best move " << record::csa::show(best_move)
00123 << "\n";
00124 std::cerr << "record " << record << "\n";
00125 if (record)
00126 {
00127 record->dump(std::cerr);
00128 }
00129 record_stack.dump();
00130 repetition_counter.history().dump();
00131 return false;
00132 }
00133
00134 void osl::search::SearchState2Core::makePV(PVVector& parent, Move m, PVVector& pv)
00135 {
00136 parent.clear();
00137 parent.push_back(m);
00138 parent.push_back(pv.begin(), pv.end());
00139 }
00140
00141
00142
00143 osl::search::
00144 SearchState2::SearchState2(const NumEffectState& s, checkmate_t& c)
00145 : SearchState2Core(s, c), root_limit(0), cur_limit(0)
00146 {
00147 }
00148
00149 osl::search::
00150 SearchState2::~SearchState2()
00151 {
00152 }
00153
00154 void osl::search::
00155 SearchState2::setState(const NumEffectState& s)
00156 {
00157 SearchState2Core::setState(s);
00158 root_limit = cur_limit = 0;
00159 }
00160
00161 int osl::search::
00162 SearchState2::countSacrificeCheck2(int history_max) const
00163 {
00164 return SacrificeCheck::count2(recordHistory(), history(), history_max);
00165 }
00166
00167 bool osl::search::
00168 SearchState2::abort(Move best_move) const
00169 {
00170 std::cerr << "cur limit " << cur_limit
00171 << " root limit " << root_limit << "\n";
00172 SearchState2Core::abort(best_move);
00173 return false;
00174 }
00175
00176 void osl::search::
00177 SearchState2::checkPointSearchAllMoves()
00178 {
00179
00180 }
00181
00182
00183
00184
00185
00186