libertyEstimator.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
libertyEstimator.h
Go to the documentation of this file.
1 /* libertyEstimator.h
2 */
3 #ifndef _LIBERTYESTIMATOR_H
4 #define _LIBERTYESTIMATOR_H
5
6 #include "osl/checkmate/proofNumberTable.h"
7 #include "osl/move.h"
8 namespace osl
9 {
10 namespace checkmate
11 {
12 struct PureLibertyEstimator
13 {
15 template <class State>
16 static void attackH(Player attacker, const State& state,
17 King8Info info, Move move,
18 unsigned int& proof_number,
19 unsigned int& disproof_number)
20 {
21 const Player defender = alt(attacker);
22 const Square king_position = state.kingSquare(defender);
23 proof_number = Proof_Number_Table.countLiberty
24 (state, info.libertyCount(), move, king_position, info);
25 disproof_number = 1;
26 }
28 template <class State>
29 static void defenseH(Player /*attacker*/, const State&, Move /*move*/,
30 unsigned int& proof_number,
31 unsigned int& disproof_number)
32 {
33 proof_number = 1;
34 disproof_number = 1;
35 }
36
37 };
42 struct LibertyEstimator
43 {
44
46 template <class State>
47 static void attackH(Player attacker, const State&, King8Info, Move move,
48 unsigned int& proof_number, unsigned int& disproof_number);
50 template <class State>
51 static void defenseH(Player attacker, const State&, Move move,
52 unsigned int& proof_number, unsigned int& disproof_number);
53 };
54
55 } // namespace checkmate
56 } // namespace osl
57
58
59 template<typename State>
60 void osl::checkmate::LibertyEstimator::
61 attackH(Player attacker, const State& state, King8Info info, Move move,
62 unsigned int& proof_number, unsigned int& disproof_number)
63 {
64 const Player defender = alt(attacker);
65 PureLibertyEstimator::attackH
66 (attacker, state, info, move, proof_number, disproof_number);
67
68 // 功罪はあるが，速くなる問題の方が多そう
69 if (state.hasMultipleEffectAt(defender, move.to()))
70 ++proof_number;
71
72 const Square from=move.from();
73 const Square to=move.to();
74 const int attack_support = state.countEffect(attacker,to);
75 const int defense_support = state.countEffect(defender,to);
76 if ((attack_support + (from.isPieceStand() ? 1 : 0)) > defense_support)
77 {
79 disproof_number=2;
80 }
81 else if (move.capturePtype()!=PTYPE_EMPTY)
82 {
84 Ptype capturePtype=unpromote(move.capturePtype());
85 if ((capturePtype == SILVER)
86 || (capturePtype == GOLD))
87 {
88 disproof_number=2;
89 }
90 else
91 {
92 proof_number+=1;
93 disproof_number=1;
94 }
95 }
96 else
97 {
98 proof_number+=1;
99 disproof_number=1;
100 }
101 }
102
103 template<typename State>
104 void osl::checkmate::LibertyEstimator::
105 defenseH(Player attacker, const State& state, Move move,
106 unsigned int& proof_number, unsigned int& disproof_number)
107 {
109 if (move.capturePtype()!=PTYPE_EMPTY)
110 {
111 proof_number=2;
112 disproof_number=1;
113 return;
114 }
115 if (move.ptype()==KING)
116 {
117 proof_number=1;
118 disproof_number=1;
119 return;
120 }
121 const Square to = move.to();
122 if ((state.countEffect(attacker,to) + (move.isDrop() ? 1 : 0))
123 <= state.countEffect(alt(attacker),to))
124 {
125 proof_number=2;
126 disproof_number=1;
127 return;
128 }
129 proof_number=1;
130 disproof_number = 2;
131 }
132
133 #endif /* _LIBERTYESTIMATOR_H */
134 // ;;; Local Variables:
135 // ;;; mode:c++
136 // ;;; c-basic-offset:2
137 // ;;; End: