My Project
libertyEstimator.h
Go to the documentation of this file.
1 /* libertyEstimator.h
2  */
3 #ifndef _LIBERTYESTIMATOR_H
4 #define _LIBERTYESTIMATOR_H
5 
7 
8 namespace osl
9 {
10  namespace checkmate
11  {
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  };
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>
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);
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>
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:
圧縮していない moveの表現 .
Definition: basic_type.h:1052
Ptype ptype() const
Definition: basic_type.h:1155
bool isDrop() const
Definition: basic_type.h:1150
Ptype capturePtype() const
Definition: basic_type.h:1180
const Square to() const
Definition: basic_type.h:1132
const Square from() const
Definition: basic_type.h:1125
bool isPieceStand() const
Definition: basic_type.h:576
敵玉の8近傍の状態を表す.
Definition: king8Info.h:29
unsigned int libertyCount() const
libertyの数
Definition: king8Info.h:82
const Liberty countLiberty(Ptype ptype, Direction d, unsigned int liberty_mask) const
dir 方向からの王手をかけた時のlibertyの予想
ProofNumberTable Proof_Number_Table
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
@ KING
Definition: basic_type.h:93
@ PTYPE_EMPTY
Definition: basic_type.h:85
@ SILVER
Definition: basic_type.h:98
@ GOLD
Definition: basic_type.h:94
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
Definition: basic_type.h:157
Player
Definition: basic_type.h:8
constexpr Player alt(Player player)
Definition: basic_type.h:13
玉の動ける場所を基本としたHの推定.
static void attackH(Player attacker, const State &, King8Info, Move move, unsigned int &proof_number, unsigned int &disproof_number)
攻撃側の move に対する proof_number と disproof_number を予想する
static void defenseH(Player attacker, const State &, Move move, unsigned int &proof_number, unsigned int &disproof_number)
防御側の move に対する proof_number と disproof_number を予想する
static void attackH(Player attacker, const State &state, King8Info info, Move move, unsigned int &proof_number, unsigned int &disproof_number)
static void defenseH(Player, const State &, Move, unsigned int &proof_number, unsigned int &disproof_number)