/usr/include/osl/ntesuki/oracleProverLight.tcc is in libosl-dev 0.6.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | /* oracleProverLight.tcc
*/
#include "osl/ntesuki/oracleProverLight.h"
#include "osl/ntesuki/ntesukiRecord.h"
#include "osl/ntesuki/ntesukiMoveGenerator.h"
#include "osl/checkmate/fixedDepthSearcher.h"
#include "osl/checkmate/fixedDepthSearcher.tcc"
#include "osl/move_classifier/safeMove.h"
#include "osl/apply_move/applyMoveWithPath.h"
#include "osl/checkmate/immediateCheckmate.h"
#include "osl/effect_util/effectUtil.h"
#ifdef NDEBUG
# include "osl/ntesuki/ntesukiMove.tcc"
# include "osl/ntesuki/ntesukiRecord.tcc"
//# include "osl/move_generator/escape.tcc"
#endif
using namespace osl;
using namespace osl::ntesuki;
/* Helper classes
*/
template <class Searcher, Player P>
class
OracleProverLight::
AttackHelper
{
Searcher* searcher;
const NtesukiRecord *record_orig;
unsigned int pass_left;
public:
bool result;
AttackHelper(Searcher* searcher,
const NtesukiRecord* record_orig,
unsigned int pass_left)
: searcher(searcher), record_orig(record_orig), pass_left(pass_left)
{}
void operator()(Square p)
{
const Player O = PlayerTraits<P>::opponent;
result = (*searcher).template defense<O>(record_orig, pass_left);
}
};
template <class Searcher, Player P>
class OracleProverLight::
DefenseHelper
{
Searcher* searcher;
const NtesukiRecord *record_orig;
unsigned int pass_left;
public:
bool result;
DefenseHelper(Searcher* searcher,
const NtesukiRecord* record_orig,
unsigned int pass_left)
: searcher(searcher), record_orig(record_orig), pass_left(pass_left)
{}
void operator()(Square p)
{
const Player O = PlayerTraits<P>::opponent;
result = (*searcher).template attack<O>(record_orig, pass_left);
}
};
/* Utility
*/
/* Still cannot see if is safe move */
template <Player P>
static bool
is_safe_move(const osl::ntesuki::OracleProverLight::state_t state,
const osl::Move& m,
int pass_left)
{
if (!m.isValid()) return false;
if (!state.isValidMove(m, false)) return false;
if (m.isDrop()) return true;
return move_classifier::SafeMove<P>::isMember(state, m.ptype(), m.from(), m.to());
}
/* adjust the captuer ptype of a move */
template <Player P>
static osl::Move
adjustMove(const osl::ntesuki::OracleProverLight::state_t state,
osl::Move candidate)
{
if (! candidate.isDrop())
{
const osl::Piece p = state.pieceOnBoard(candidate.to());
candidate=setCapture(candidate,p);
}
return candidate;
}
/* The worker
*/
/* attack */
template <Player P>
bool
OracleProverLight::
attack(const NtesukiRecord* record_orig,
const unsigned int pass_left)
{
const Player attacker = P;
ntesuki_assert(P == state.turn());
if (!record_orig ||
!record_orig->getValue<attacker>(pass_left)
.isCheckmateSuccess() ||
!record_orig->getBestMove<attacker>(pass_left).isValid())
{
return false;
}
Move check_move;
FixedDepthSearcher fixed_searcher(state);
if (!state.inCheck(P) &&
fixed_searcher.hasCheckmateMove<P>(NtesukiRecord::fixed_search_depth,
check_move).isCheckmateSuccess())
{
/* Immediate Checkmate */
return true;
}
/* Simulation 元が immediate checkmate ならこの先は simulate できない */
const NtesukiMove best_move_orig = record_orig->getBestMove<attacker>(pass_left);
if (best_move_orig.isImmediateCheckmate())
{
return false;
}
/* n が少ないときの結果を参照 */
if ((pass_left > 0) &&
record_orig->getValue<attacker>(pass_left - 1).isCheckmateSuccess())
{
return attack<P>(record_orig, pass_left - 1);
}
const Move move = adjustMove<P>(state, best_move_orig.move());
/* invalid move となってしまった */
if (!is_safe_move<P>(state, move, pass_left))
{
return false;
}
const bool move_is_check = (move_classifier::PlayerMoveAdaptor<move_classifier::Check>::
isMember(state, move));
/* 即詰探索中は王手のみ読む */
if(0 == pass_left && !move_is_check)
{
return false;
}
/* 以前は check だったのが今は違ってしまった・その逆 */
if (best_move_orig.isCheck() != move_is_check)
{
return false;
}
/* 以前の bestMove を実行 */
const NtesukiRecord* record_child_orig = table.findWithMoveConst(record_orig,
best_move_orig);
if (!record_child_orig)
{
//ntesuki_assert (record_orig->isBySimulation());
return false;
}
//ntesuki_assert(record_child_orig);
AttackHelper<OracleProverLight, P> helper(this,
record_child_orig,
pass_left);
TRY_DFPN;
ApplyMoveWithPath<P>::doUndoMove(state, path, move, helper);
CATCH_DFPN;
return helper.result;
}
/* defense */
template <Player P>
bool OracleProverLight::
defense(const NtesukiRecord* record_orig,
const unsigned int pass_left)
{
const Player attacker = PlayerTraits<P>::opponent;
ntesuki_assert(P == state.turn());
if (!record_orig ||
!record_orig->getValue<attacker>(pass_left)
.isCheckmateSuccess())
{
return false;
}
/* 攻撃側に王手がかかっていないか調べる */
if (state.inCheck(attacker))
{
return false;
}
/* 現在王手になっているかどうか */
if ((pass_left == 0) &&
!state.inCheck(P))
{
return false;
}
/* n が少ないときの結果を参照 */
if (pass_left > 0 &&
record_orig->getValue<attacker>(pass_left - 1).isCheckmateSuccess())
{
return defense<P>(record_orig, pass_left - 1);
}
/* 手の生成 */
NtesukiMoveList moves;
mg->generateSlow(P, state, moves);
if (moves.empty()) return true;
/* 受ける手の実行 */
for (NtesukiMoveList::iterator move_it = moves.begin();
move_it != moves.end(); move_it++)
{
NtesukiMove& move = *move_it;
if (isscheme != NtesukiRecord::normal_is &&
isscheme != NtesukiRecord::delay_is &&
move.isCheck() && pass_left > 0) continue;
ntesuki_assert(move.isPass() || move.isNormal());
const NtesukiRecord *record_child_orig = table.findWithMoveConst(record_orig, move);
if (!record_child_orig ||
!record_child_orig->getValue<attacker>(pass_left).isCheckmateSuccess())
{
return false;
}
int pass_left_child = pass_left;
if (move.isPass()) --pass_left_child;
DefenseHelper<OracleProverLight, P> helper(this, record_child_orig, pass_left_child);
TRY_DFPN;
ApplyMoveWithPath<P>::doUndoMoveOrPass(state, path, move.move(), helper);
CATCH_DFPN;
if (false == helper.result) return false;
}
return true;
}
/* Publice interface
*/
template <Player P>
bool
OracleProverLight::
startFromAttack(NtesukiRecord* record,
const NtesukiRecord* record_orig,
const unsigned int pass_left)
{
const Player attacker = P;
if (!record || !record_orig) return false;
if (!record->getPieceStand<attacker>().isSuperiorOrEqualTo
(record_orig->getPDPieces<attacker>(pass_left)))
{
return false;
}
ntesuki_assert(record_orig->getValue<attacker>(pass_left).isCheckmateSuccess());
if (attack<P>(record_orig, pass_left))
{
#ifndef NDEBUG
const NtesukiMove m = (record_orig->getBestMove<attacker>(pass_left));
ntesuki_assert(m.isValid());
ntesuki_assert(!m.isImmediateCheckmate());
#endif
TRY_DFPN;
const PieceStand ps = record->getPieceStand<attacker>();
record->setResult<attacker>(pass_left, ProofDisproof::Checkmate(),
record_orig->getBestMove<attacker>(pass_left),
true, &ps);
CATCH_DFPN;
return true;
}
return false;
}
template <Player P>
bool
OracleProverLight::
startFromDefense(NtesukiRecord* record,
const NtesukiRecord* record_orig,
const unsigned int pass_left)
{
const Player attacker = PlayerTraits<P>::opponent;
if (!record || !record_orig) return false;
if (!record->getPieceStand<attacker>().isSuperiorOrEqualTo
(record_orig->getPDPieces<attacker>(pass_left)))
{
return false;
}
ntesuki_assert(record_orig->getValue<attacker>(pass_left).isCheckmateSuccess());
if (defense<P>(record_orig, pass_left))
{
TRY_DFPN;
const PieceStand ps = record->getPieceStand<attacker>();
record->setResult<attacker>(pass_left, ProofDisproof::Checkmate(),
record_orig->getBestMove<attacker>(pass_left),
true, &ps);
CATCH_DFPN;
return true;
}
return false;
}
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|