| 1 |
/* proofOracle.h |
| 2 |
*/ |
| 3 |
#ifndef _PROOFORACLE_H |
| 4 |
#define _PROOFORACLE_H |
| 5 |
|
| 6 |
#include "checkHashRecord.h" |
| 7 |
#include "checkAssert.h" |
| 8 |
#include <cstddef> |
| 9 |
namespace osl |
| 10 |
{ |
| 11 |
namespace checkmate |
| 12 |
{ |
| 13 |
template <Player Attacker> |
| 14 |
struct ProofOracleDefense; |
| 15 |
|
| 16 |
/** |
| 17 |
* 詰む類似局面 (攻方). |
| 18 |
* OracleProver が使用 |
| 19 |
*/ |
| 20 |
template <Player Attacker> |
| 21 |
struct ProofOracleAttack |
| 22 |
{ |
| 23 |
const CheckHashRecord *guide; |
| 24 |
explicit ProofOracleAttack(const CheckHashRecord *g=0) : guide(g) |
| 25 |
{ |
| 26 |
check_assert((!guide) |
| 27 |
|| ((guide->proofDisproof().isCheckmateSuccess() |
| 28 |
&& (guide->hasBestMove() |
| 29 |
&& guide->getBestMove()->move.player() == Attacker)) |
| 30 |
|| (guide->dump(), 0))); |
| 31 |
// (guide->proofDisproof() == NoEscape) |
| 32 |
} |
| 33 |
Move oracle() |
| 34 |
{ |
| 35 |
check_assert(guide && guide->hasBestMove()); |
| 36 |
return guide->getBestMove()->move; |
| 37 |
} |
| 38 |
inline ProofOracleDefense<Attacker> expandOracle(); |
| 39 |
bool isValid() const { return guide; } |
| 40 |
}; |
| 41 |
|
| 42 |
/** |
| 43 |
* 詰む類似局面 (受方). |
| 44 |
* OracleProver や CheckmateSearcher が使用 |
| 45 |
*/ |
| 46 |
template <Player Attacker> |
| 47 |
struct ProofOracleDefense |
| 48 |
{ |
| 49 |
const CheckHashRecord *guide; |
| 50 |
explicit ProofOracleDefense(const CheckHashRecord *g=0) : guide(g) |
| 51 |
{ |
| 52 |
check_assert((!guide) |
| 53 |
|| (guide->proofDisproof().isCheckmateSuccess() |
| 54 |
|| (g->dump(), 0))); |
| 55 |
} |
| 56 |
|
| 57 |
/** bestMove の後に受方が defense をしたときのoracle */ |
| 58 |
ProofOracleAttack<Attacker> expandOracle(Move defense) |
| 59 |
{ |
| 60 |
check_assert(guide); |
| 61 |
check_assert(alt(defense.player()) == Attacker); |
| 62 |
const CheckMoveList& moves |
| 63 |
= (guide->finalByDominance() |
| 64 |
? guide->finalByDominance()->moves |
| 65 |
: guide->moves); |
| 66 |
for (CheckMoveList::const_iterator p=moves.begin(); |
| 67 |
p!=moves.end(); ++p) |
| 68 |
{ |
| 69 |
if (p->move == defense) |
| 70 |
{ |
| 71 |
check_assert(p->record || (guide->dump(), 0)); |
| 72 |
check_assert(p->record->proofDisproof().isCheckmateSuccess() |
| 73 |
|| (guide->dump(), 0)); |
| 74 |
return ProofOracleAttack<Attacker>(p->record); |
| 75 |
} |
| 76 |
} |
| 77 |
if (defense.isDrop()) |
| 78 |
{ |
| 79 |
const Square to = defense.to(); |
| 80 |
for (CheckMoveList::const_iterator p=moves.begin(); |
| 81 |
p!=moves.end(); ++p) |
| 82 |
{ |
| 83 |
// TODO: 似た駒から.. |
| 84 |
if (p->move.isDrop() && p->move.to() == to) |
| 85 |
{ |
| 86 |
check_assert(p->record || (guide->dump(), 0)); |
| 87 |
check_assert(p->record->proofDisproof().isCheckmateSuccess() |
| 88 |
|| (guide->dump(), 0)); |
| 89 |
return ProofOracleAttack<Attacker>(p->record); |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
return ProofOracleAttack<Attacker>(0); |
| 94 |
} |
| 95 |
bool isValid() const { return guide; } |
| 96 |
}; |
| 97 |
|
| 98 |
template <Player Attacker> inline |
| 99 |
ProofOracleDefense<Attacker> ProofOracleAttack<Attacker>::expandOracle() |
| 100 |
{ |
| 101 |
check_assert(guide); |
| 102 |
const CheckHashRecord *nextGuide =0; |
| 103 |
if (guide->hasBestMove() && guide->getBestMove()->record |
| 104 |
&& guide->getBestMove()->record->proofDisproof().isCheckmateSuccess()) |
| 105 |
nextGuide = guide->getBestMove()->record; |
| 106 |
return ProofOracleDefense<Attacker>(nextGuide); |
| 107 |
} |
| 108 |
} // namespace checkmate |
| 109 |
} // namespace osl |
| 110 |
|
| 111 |
#endif /* _PROOFORACLE_H */ |
| 112 |
// ;;; Local Variables: |
| 113 |
// ;;; mode:c++ |
| 114 |
// ;;; c-basic-offset:2 |
| 115 |
// ;;; End: |