5 #include <boost/ptr_container/ptr_vector.hpp>
10 DfpnParallel::DfpnParallel(
size_t threads)
11 : table(0), num_threads(threads), state(0)
15 workers.reset(
new Dfpn[num_threads]);
16 for (
size_t i=0; i<num_threads; ++i)
21 DfpnParallel::~DfpnParallel()
29 DfpnParallel::setTable(DfpnTable *new_table)
32 for (
size_t i=0; i<num_threads; ++i)
38 DfpnParallel::hasCheckmateMove(
const NumEffectState& state,
const HashKey& key,
40 Move last_move, std::vector<Move> *pv)
43 return hasCheckmateMove(state, key, path, limit, best_move, proof, last_move, pv);
46 struct osl::checkmate::DfpnParallel::AttackWorker
51 AttackWorker(DfpnParallel *p,
int id)
55 void operator()()
const
57 assert(! parent->shared.data[
thread_id].restart);
58 WorkerData& work = parent->worker_data[
thread_id];
59 work.result = parent->workers[
thread_id].hasCheckmateMove
60 (*(parent->state), parent->key, parent->path,
61 parent->limit, work.best_move, work.proof, parent->last_move);
68 DfpnParallel::hasCheckmateMove(
const NumEffectState& state,
const HashKey& key,
69 const PathEncoding& path,
size_t limit, Move& best_move, PieceStand& proof,
70 Move last_move, std::vector<Move> *pv)
75 this->last_move = last_move;
78 worker_data.reset(
new WorkerData[num_threads]);
79 boost::ptr_vector<std::thread> threads;
80 for (
size_t i=0; i<num_threads; ++i)
81 threads.push_back(
new std::thread(AttackWorker(
this, i)));
84 for (
size_t i=0; i<num_threads; ++i) {
87 || (worker_data[i].result.proof() >= min_proof
88 && ! worker_data[i].result.isFinal()))
90 ret = worker_data[i].result;
91 min_proof = ret.proof();
92 best_move = worker_data[i].best_move;
93 proof = worker_data[i].proof;
95 if (pv && ret.isCheckmateSuccess()) {
96 ProofTreeDepthDfpn analyzer(*
table);
97 analyzer.retrievePV(state,
true, *pv);
102 struct osl::checkmate::DfpnParallel::DefenseWorker
104 DfpnParallel *parent;
107 DefenseWorker(DfpnParallel *p,
int id)
111 void operator()()
const
113 WorkerData& work = parent->worker_data[
thread_id];
114 work.result = parent->workers[
thread_id].hasEscapeMove
115 (*(parent->state), parent->key, parent->path,
116 parent->limit, parent->last_move);
122 DfpnParallel::hasEscapeMove(
const NumEffectState& state,
124 size_t limit, Move last_move)
126 this->state = &state;
129 this->last_move = last_move;
132 worker_data.reset(
new WorkerData[num_threads]);
133 boost::ptr_vector<std::thread> threads;
134 for (
size_t i=0; i<num_threads; ++i)
135 threads.push_back(
new std::thread(DefenseWorker(
this, i)));
138 for (
size_t i=0; i<num_threads; ++i) {
140 if (worker_data[i].result.disproof() >= min_disproof)
142 ret = worker_data[i].result;
143 min_disproof = ret.disproof();
148 size_t osl::checkmate::
149 DfpnParallel::nodeCount()
const
152 for (
size_t i=0; i<num_threads; ++i)
158 void osl::checkmate::
160 const NumEffectState& src,
const std::vector<Move>& moves)
const
163 workers[0].analyze(path, src, moves);