proofDisproof.h
Go to the documentation of this file.
#ifndef _PROOF_DISPROOF_H
#define _PROOF_DISPROOF_H
#include "osl/basic_type.h"
#include <cassert>
#include <iosfwd>
namespace osl
{
namespace checkmate
{
class ProofDisproof
{
unsigned long long pdp;
public:
enum {
PROOF_SHIFT = 32,
DISPROOF_MASK = 0xffffffffu,
PROOF_MAX = (0xffffffffu / 16),
DISPROOF_MAX = (0xffffffffu / 16),
NO_ESCAPE_DISPROOF = (DISPROOF_MAX - 1),
CHECK_MATE_DISPROOF = (DISPROOF_MAX - 2),
NO_CHECK_MATE_PROOF = (PROOF_MAX - 1),
PAWN_CHECK_MATE_PROOF = (PROOF_MAX - 2),
LOOP_DETECTION_PROOF = (PROOF_MAX - 3),
ATTACK_BACK_PROOF = (PROOF_MAX - 4),
};
private:
static void testConsistency();
public:
enum {
DISPROOF_LIMIT = (DISPROOF_MAX - 3),
PROOF_LIMIT = (PROOF_MAX - 5),
};
private:
static unsigned long long
compose(unsigned long long proof, unsigned long long disproof)
{
return (proof << PROOF_SHIFT) + disproof;
}
ProofDisproof(unsigned long long value) : pdp(value)
{
}
static const ProofDisproof
make(unsigned int proof, unsigned int disproof)
{
return ProofDisproof(compose(proof, disproof));
}
public:
ProofDisproof() : pdp(compose(1, 1))
{
}
ProofDisproof(unsigned int proof, unsigned int disproof)
: pdp(compose(proof,disproof))
{
assert(proof < PROOF_MAX);
assert(disproof < DISPROOF_MAX);
assert(proof || disproof);
assert((proof == 0) ^ (disproof < DISPROOF_LIMIT));
assert((disproof == 0) ^ (proof < PROOF_LIMIT));
}
static const ProofDisproof makeDirect(unsigned long long value) { return ProofDisproof(value); }
// constants
static const ProofDisproof NoEscape() { return ProofDisproof(0, NO_ESCAPE_DISPROOF); }
static const ProofDisproof Checkmate() { return ProofDisproof(0, CHECK_MATE_DISPROOF); }
static const ProofDisproof NoCheckmate() { return ProofDisproof(NO_CHECK_MATE_PROOF, 0); }
static const ProofDisproof PawnCheckmate() { return ProofDisproof(PAWN_CHECK_MATE_PROOF, 0); }
static const ProofDisproof LoopDetection() { return ProofDisproof(LOOP_DETECTION_PROOF, 0); }
static const ProofDisproof AttackBack() { return ProofDisproof(ATTACK_BACK_PROOF, 0); }
static const ProofDisproof Unknown () { return ProofDisproof(1, 1); }
static const ProofDisproof Bottom () { return make(PROOF_MAX, DISPROOF_MAX); }
unsigned int proof() const { return pdp >> PROOF_SHIFT; }
unsigned int disproof() const { return pdp & DISPROOF_MASK; }
bool isCheckmateSuccess() const { return proof()==0; }
bool isCheckmateFail() const { return disproof()==0; }
bool isFinal() const { return isCheckmateSuccess() || isCheckmateFail(); }
bool isUnknown() const { return !isFinal(); }
bool isPawnDropFoul(Move move) const
{
return (pdp == NoEscape().pdp) && move.isNormal() && move.isDrop()
&& (move.ptype()==PAWN);
}
bool isLoopDetection() const { return pdp == LoopDetection().pdp; }
unsigned long long ulonglongValue() const { return pdp; }
static const unsigned int BigProofNumber=PROOF_MAX;
bool isBetterForAttack(const ProofDisproof& r) const
{
const unsigned int lp = proof();
const unsigned int rp = r.proof();
if (lp != rp)
return lp < rp;
return disproof() > r.disproof();
}
bool isBetterForDefense(const ProofDisproof& r) const
{
const unsigned int ld = disproof();
const unsigned int rd = r.disproof();
if (ld != rd)
return ld < rd;
return proof() > r.proof();
}
const ProofDisproof& betterForAttack(const ProofDisproof& r) const
{
return (isBetterForAttack(r) ? *this : r);
}
const ProofDisproof& betterForDefense(const ProofDisproof& r) const
{
return (isBetterForDefense(r) ? *this : r);
}
};
inline bool operator==(const ProofDisproof& l, const ProofDisproof& r)
{
return l.ulonglongValue() == r.ulonglongValue();
}
inline bool operator!=(const ProofDisproof& l, const ProofDisproof& r)
{
return ! (l == r);
}
inline bool operator<(const ProofDisproof& l, const ProofDisproof& r)
{
return l.ulonglongValue() < r.ulonglongValue();
}
std::ostream& operator<<(std::ostream& os,
const ProofDisproof& proofDisproof);
} // namespace checkmate
using checkmate::ProofDisproof;
} // namespace osl
#endif // _PROOF_DISPROOF_H
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
basic_type.h
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::ptype
Ptype ptype() const
Definition basic_type.h:1155
osl::Move::isDrop
bool isDrop() const
Definition basic_type.h:1150
osl::Move::isNormal
bool isNormal() const
INVALID でも PASS でもない.
Definition basic_type.h:1088
osl::checkmate::ProofDisproof
証明数(proof number)と反証数(disproof number).
Definition proofDisproof.h:17
osl::checkmate::ProofDisproof::isCheckmateFail
bool isCheckmateFail() const
Definition proofDisproof.h:87
osl::checkmate::ProofDisproof::PAWN_CHECK_MATE_PROOF
@ PAWN_CHECK_MATE_PROOF
Definition proofDisproof.h:30
osl::checkmate::ProofDisproof::NO_ESCAPE_DISPROOF
@ NO_ESCAPE_DISPROOF
反証数の定数: 詰んだ時には，詰の種類の区別に利用
Definition proofDisproof.h:26
osl::checkmate::ProofDisproof::ATTACK_BACK_PROOF
@ ATTACK_BACK_PROOF
Definition proofDisproof.h:32
osl::checkmate::ProofDisproof::DISPROOF_MAX
@ DISPROOF_MAX
Definition proofDisproof.h:24
osl::checkmate::ProofDisproof::NO_CHECK_MATE_PROOF
@ NO_CHECK_MATE_PROOF
証明数の定数: 反証された時には，不詰の種類の区別に利用
Definition proofDisproof.h:29
osl::checkmate::ProofDisproof::CHECK_MATE_DISPROOF
@ CHECK_MATE_DISPROOF
Definition proofDisproof.h:27
osl::checkmate::ProofDisproof::PROOF_SHIFT
@ PROOF_SHIFT
Definition proofDisproof.h:21
osl::checkmate::ProofDisproof::PROOF_MAX
@ PROOF_MAX
Definition proofDisproof.h:23
osl::checkmate::ProofDisproof::LOOP_DETECTION_PROOF
@ LOOP_DETECTION_PROOF
Definition proofDisproof.h:31
osl::checkmate::ProofDisproof::DISPROOF_MASK
@ DISPROOF_MASK
Definition proofDisproof.h:22
osl::checkmate::ProofDisproof::isFinal
bool isFinal() const
Definition proofDisproof.h:88
osl::checkmate::ProofDisproof::PawnCheckmate
static const ProofDisproof PawnCheckmate()
Definition proofDisproof.h:77
osl::checkmate::ProofDisproof::AttackBack
static const ProofDisproof AttackBack()
Definition proofDisproof.h:79
osl::checkmate::ProofDisproof::compose
static unsigned long long compose(unsigned long long proof, unsigned long long disproof)
Definition proofDisproof.h:45
osl::checkmate::ProofDisproof::LoopDetection
static const ProofDisproof LoopDetection()
Definition proofDisproof.h:78
osl::checkmate::ProofDisproof::ulonglongValue
unsigned long long ulonglongValue() const
Definition proofDisproof.h:99
osl::checkmate::ProofDisproof::Bottom
static const ProofDisproof Bottom()
攻方にも受方にも不都合な仮想的な数
Definition proofDisproof.h:82
osl::checkmate::ProofDisproof::ProofDisproof
ProofDisproof()
Definition proofDisproof.h:59
osl::checkmate::ProofDisproof::NoEscape
static const ProofDisproof NoEscape()
Definition proofDisproof.h:74
osl::checkmate::ProofDisproof::NoCheckmate
static const ProofDisproof NoCheckmate()
Definition proofDisproof.h:76
osl::checkmate::ProofDisproof::BigProofNumber
static const unsigned int BigProofNumber
Definition proofDisproof.h:101
osl::checkmate::ProofDisproof::betterForDefense
const ProofDisproof & betterForDefense(const ProofDisproof &r) const
受方に都合が良い方を返す
Definition proofDisproof.h:135
osl::checkmate::ProofDisproof::pdp
unsigned long long pdp
Definition proofDisproof.h:18
osl::checkmate::ProofDisproof::makeDirect
static const ProofDisproof makeDirect(unsigned long long value)
Definition proofDisproof.h:71
osl::checkmate::ProofDisproof::ProofDisproof
ProofDisproof(unsigned long long value)
range check をしない private バージョン
Definition proofDisproof.h:50
osl::checkmate::ProofDisproof::ProofDisproof
ProofDisproof(unsigned int proof, unsigned int disproof)
Definition proofDisproof.h:62
osl::checkmate::ProofDisproof::isBetterForAttack
bool isBetterForAttack(const ProofDisproof &r) const
this が r より攻方に都合が良い時に真
Definition proofDisproof.h:106
osl::checkmate::ProofDisproof::isCheckmateSuccess
bool isCheckmateSuccess() const
Definition proofDisproof.h:86
osl::checkmate::ProofDisproof::betterForAttack
const ProofDisproof & betterForAttack(const ProofDisproof &r) const
攻方に都合が良い方を返す
Definition proofDisproof.h:128
osl::checkmate::ProofDisproof::isLoopDetection
bool isLoopDetection() const
Definition proofDisproof.h:97
osl::checkmate::ProofDisproof::disproof
unsigned int disproof() const
Definition proofDisproof.h:85
osl::checkmate::ProofDisproof::isUnknown
bool isUnknown() const
Definition proofDisproof.h:89
osl::checkmate::ProofDisproof::testConsistency
static void testConsistency()
Definition proofDisproof.cc:5
osl::checkmate::ProofDisproof::proof
unsigned int proof() const
Definition proofDisproof.h:84
osl::checkmate::ProofDisproof::isPawnDropFoul
bool isPawnDropFoul(Move move) const
打歩詰めなら真
Definition proofDisproof.h:92
osl::checkmate::ProofDisproof::make
static const ProofDisproof make(unsigned int proof, unsigned int disproof)
Definition proofDisproof.h:54
osl::checkmate::ProofDisproof::Checkmate
static const ProofDisproof Checkmate()
Definition proofDisproof.h:75
osl::checkmate::ProofDisproof::PROOF_LIMIT
@ PROOF_LIMIT
通常の証明数の上限
Definition proofDisproof.h:41
osl::checkmate::ProofDisproof::DISPROOF_LIMIT
@ DISPROOF_LIMIT
通常の反証数の上限
Definition proofDisproof.h:39
osl::checkmate::ProofDisproof::isBetterForDefense
bool isBetterForDefense(const ProofDisproof &r) const
this が r より受方に都合が良い時に真
Definition proofDisproof.h:117
osl::checkmate::ProofDisproof::Unknown
static const ProofDisproof Unknown()
Definition proofDisproof.h:80
osl::checkmate
Definition king8Info.h:12
osl::checkmate::operator<<
std::ostream & operator<<(std::ostream &, King8Info)
Definition king8Info.cc:10
osl::checkmate::operator!=
bool operator!=(const ProofDisproof &l, const ProofDisproof &r)
Definition proofDisproof.h:144
osl::checkmate::operator==
bool operator==(const ProofDisproof &l, const ProofDisproof &r)
Definition proofDisproof.h:140
osl::checkmate::operator<
bool operator<(const ProofDisproof &l, const ProofDisproof &r)
Definition proofDisproof.h:148
osl
Definition additionalEffect.h:6
osl::PAWN
@ PAWN
Definition basic_type.h:95