My Project
proofDisproof.h
Go to the documentation of this file.
1#ifndef _PROOF_DISPROOF_H
2#define _PROOF_DISPROOF_H
3
4#include "osl/basic_type.h"
5#include <cassert>
6#include <iosfwd>
7namespace osl
8{
9 namespace checkmate
10 {
17 {
18 unsigned long long pdp;
19 public:
20 enum {
22 DISPROOF_MASK = 0xffffffffu,
23 PROOF_MAX = (0xffffffffu / 16),
24 DISPROOF_MAX = (0xffffffffu / 16),
33 };
34 private:
35 static void testConsistency();
36 public:
37 enum {
42 };
43 private:
44 static unsigned long long
45 compose(unsigned long long proof, unsigned long long disproof)
46 {
47 return (proof << PROOF_SHIFT) + disproof;
48 }
50 ProofDisproof(unsigned long long value) : pdp(value)
51 {
52 }
53 static const ProofDisproof
54 make(unsigned int proof, unsigned int disproof)
55 {
57 }
58 public:
60 {
61 }
62 ProofDisproof(unsigned int proof, unsigned int disproof)
64 {
65 assert(proof < PROOF_MAX);
66 assert(disproof < DISPROOF_MAX);
67 assert(proof || disproof);
68 assert((proof == 0) ^ (disproof < DISPROOF_LIMIT));
69 assert((disproof == 0) ^ (proof < PROOF_LIMIT));
70 }
71 static const ProofDisproof makeDirect(unsigned long long value) { return ProofDisproof(value); }
72
73 // constants
80 static const ProofDisproof Unknown () { return ProofDisproof(1, 1); }
82 static const ProofDisproof Bottom () { return make(PROOF_MAX, DISPROOF_MAX); }
83
84 unsigned int proof() const { return pdp >> PROOF_SHIFT; }
85 unsigned int disproof() const { return pdp & DISPROOF_MASK; }
86 bool isCheckmateSuccess() const { return proof()==0; }
87 bool isCheckmateFail() const { return disproof()==0; }
88 bool isFinal() const { return isCheckmateSuccess() || isCheckmateFail(); }
89 bool isUnknown() const { return !isFinal(); }
90
92 bool isPawnDropFoul(Move move) const
93 {
94 return (pdp == NoEscape().pdp) && move.isNormal() && move.isDrop()
95 && (move.ptype()==PAWN);
96 }
97 bool isLoopDetection() const { return pdp == LoopDetection().pdp; }
98
99 unsigned long long ulonglongValue() const { return pdp; }
100
101 static const unsigned int BigProofNumber=PROOF_MAX;
102
106 bool isBetterForAttack(const ProofDisproof& r) const
107 {
108 const unsigned int lp = proof();
109 const unsigned int rp = r.proof();
110 if (lp != rp)
111 return lp < rp;
112 return disproof() > r.disproof();
113 }
118 {
119 const unsigned int ld = disproof();
120 const unsigned int rd = r.disproof();
121 if (ld != rd)
122 return ld < rd;
123 return proof() > r.proof();
124 }
129 {
130 return (isBetterForAttack(r) ? *this : r);
131 }
136 {
137 return (isBetterForDefense(r) ? *this : r);
138 }
139 };
140 inline bool operator==(const ProofDisproof& l, const ProofDisproof& r)
141 {
142 return l.ulonglongValue() == r.ulonglongValue();
143 }
144 inline bool operator!=(const ProofDisproof& l, const ProofDisproof& r)
145 {
146 return ! (l == r);
147 }
148 inline bool operator<(const ProofDisproof& l, const ProofDisproof& r)
149 {
150 return l.ulonglongValue() < r.ulonglongValue();
151 }
152
153 std::ostream& operator<<(std::ostream& os,
154 const ProofDisproof& proofDisproof);
155 } // namespace checkmate
156
157 using checkmate::ProofDisproof;
158} // namespace osl
159#endif // _PROOF_DISPROOF_H
160// ;;; Local Variables:
161// ;;; mode:c++
162// ;;; c-basic-offset:2
163// ;;; End:
圧縮していない moveの表現 .
Ptype ptype() const
bool isDrop() const
bool isNormal() const
INVALID でも PASS でもない.
証明数(proof number)と反証数(disproof number).
static const ProofDisproof PawnCheckmate()
static const ProofDisproof AttackBack()
static unsigned long long compose(unsigned long long proof, unsigned long long disproof)
static const ProofDisproof LoopDetection()
unsigned long long ulonglongValue() const
static const ProofDisproof Bottom()
攻方にも受方にも不都合な仮想的な数
static const ProofDisproof NoEscape()
@ NO_ESCAPE_DISPROOF
反証数の定数: 詰んだ時には,詰の種類の区別に利用
@ NO_CHECK_MATE_PROOF
証明数の定数: 反証された時には,不詰の種類の区別に利用
static const ProofDisproof NoCheckmate()
static const unsigned int BigProofNumber
const ProofDisproof & betterForDefense(const ProofDisproof &r) const
受方に都合が良い方を返す
static const ProofDisproof makeDirect(unsigned long long value)
ProofDisproof(unsigned long long value)
range check をしない private バージョン
ProofDisproof(unsigned int proof, unsigned int disproof)
bool isBetterForAttack(const ProofDisproof &r) const
this が r より攻方に都合が良い時に真
@ PROOF_LIMIT
通常の証明数の上限
@ DISPROOF_LIMIT
通常の反証数の上限
const ProofDisproof & betterForAttack(const ProofDisproof &r) const
攻方に都合が良い方を返す
unsigned int disproof() const
unsigned int proof() const
bool isPawnDropFoul(Move move) const
打歩詰めなら真
static const ProofDisproof make(unsigned int proof, unsigned int disproof)
static const ProofDisproof Checkmate()
bool isBetterForDefense(const ProofDisproof &r) const
this が r より受方に都合が良い時に真
static const ProofDisproof Unknown()
std::ostream & operator<<(std::ostream &, King8Info)
Definition king8Info.cc:10
bool operator!=(const ProofDisproof &l, const ProofDisproof &r)
bool operator==(const ProofDisproof &l, const ProofDisproof &r)
bool operator<(const ProofDisproof &l, const ProofDisproof &r)
@ PAWN
Definition basic_type.h:95