My Project
king8Info.h
Go to the documentation of this file.
1/* king8Info.h
2 */
3#ifndef OSL_CHECKMATE_KING8INFO_H
4#define OSL_CHECKMATE_KING8INFO_H
5
8#include <iosfwd>
9namespace osl
10{
11 namespace checkmate
12 {
29 {
30 uint64_t value;
31 public:
32 explicit King8Info(uint64_t v) : value(v)
33 {
34 }
35
36 template<Player P>
37 static const King8Info make(NumEffectState const& state,Square king, PieceMask pinned);
38 template<Player P>
39 static const King8Info make(NumEffectState const& state,Square king);
40
42 static const King8Info make(Player attack, NumEffectState const& state);
44 static const King8Info makeWithPin(Player attack, NumEffectState const& state,
45 const PieceMask& pinned);
46 uint64_t uint64Value() const { return value; }
47
49 unsigned int dropCandidate() const
50 {
51 return (unsigned int)(value&0xffull);
52 }
54 unsigned int liberty() const
55 {
56 return (unsigned int)((value>>8)&0xffull);
57 }
59 unsigned int libertyDropMask() const
60 {
61 return (unsigned int)(value&0xffffull);
62 }
64 unsigned int libertyCandidate() const
65 {
66 return (unsigned int)((value>>16)&0xffull);
67 }
69 unsigned int moveCandidate2() const
70 {
71 return (unsigned int)((value>>24)&0xffull);
72 }
73 unsigned int spaces() const
74 {
75 return (unsigned int)((value>>32)&0xffull);
76 }
77 unsigned int moves() const
78 {
79 return (unsigned int)((value>>40)&0xffull);
80 }
82 unsigned int libertyCount() const
83 {
84 return (unsigned int)((value>>48)&0xfull);
85 }
86 template<Player P,Direction Dir>
87 unsigned int moveCandidateDir(NumEffectState const& state,Square target) const{
88 if((value & (1ull<<(24+Dir)))==0) return 0;
90 if(state.countEffect(P,pos)<2 &&
91 !effect_util::AdditionalEffect::hasEffect(state,pos,P)) return 0;
92 return 1;
93 }
94 template<Player P>
95 unsigned int countMoveCandidate(NumEffectState const& state) const
96 {
97 const Player altP=alt(P);
98 Square king=state.kingSquare<altP>();
99 return moveCandidateDir<P,UL>(state,king)+
100 moveCandidateDir<P,U>(state,king)+
101 moveCandidateDir<P,UR>(state,king)+
102 moveCandidateDir<P,L>(state,king)+
103 moveCandidateDir<P,R>(state,king)+
104 moveCandidateDir<P,DL>(state,king)+
105 moveCandidateDir<P,D>(state,king)+
106 moveCandidateDir<P,DR>(state,king);
107 }
108 unsigned int countMoveCandidate(Player player, NumEffectState const& state) const
109 {
110 if(player==BLACK) return countMoveCandidate<BLACK>(state);
111 else return countMoveCandidate<WHITE>(state);
112 }
113 template<Player P>
114 unsigned int moveCandidateMask(NumEffectState const& state) const
115 {
116 const Player altP=alt(P);
117 Square king=state.kingSquare<altP>();
118 return (moveCandidateDir<P,UL>(state,king)<<UL)+
119 (moveCandidateDir<P,U>(state,king)<<U)+
120 (moveCandidateDir<P,UR>(state,king)<<UR)+
121 (moveCandidateDir<P,L>(state,king)<<L)+
122 (moveCandidateDir<P,R>(state,king)<<R)+
123 (moveCandidateDir<P,DL>(state,king)<<DL)+
124 (moveCandidateDir<P,D>(state,king)<<D)+
125 (moveCandidateDir<P,DR>(state,king)<<DR);
126 }
127 template<Player P>
128 bool hasMoveCandidate(NumEffectState const& state) const
129 {
130 const Player altP=alt(P);
131 Square king=state.kingSquare<altP>();
132 if(moveCandidateDir<P,U>(state,king)!=0) return true;
133 if(moveCandidateDir<P,UL>(state,king)!=0) return true;
134 if(moveCandidateDir<P,UR>(state,king)!=0) return true;
135 if(moveCandidateDir<P,L>(state,king)!=0) return true;
136 if(moveCandidateDir<P,R>(state,king)!=0) return true;
137 if(moveCandidateDir<P,D>(state,king)!=0) return true;
138 if(moveCandidateDir<P,DL>(state,king)!=0) return true;
139 if(moveCandidateDir<P,DR>(state,king)!=0) return true;
140 return false;
141 }
142 private:
150 template<Player P,Direction Dir>
151 static uint64_t
152#ifdef __GNUC__
153 __attribute__ ((pure))
154#endif
155 hasEffectMask(NumEffectState const& state,Square target, PieceMask pinned,
156 PieceMask on_board_defense);
157 };
158
159 std::ostream& operator<<(std::ostream&, King8Info);
160 } // namespace checkmate
161 using checkmate::King8Info;
162} // namespace osl
163
164#endif /* OSL_CHECKMATE_KING8INFO_H */
165// ;;; Local Variables:
166// ;;; mode:c++
167// ;;; c-basic-offset:2
168// ;;; End:
169
利きを持つ局面
int countEffect(Player player, Square target) const
利きの数を数える.
駒番号のビットセット.
Definition pieceMask.h:21
Square kingSquare() const
Definition simpleState.h:94
敵玉の8近傍の状態を表す.
Definition king8Info.h:29
uint64_t uint64Value() const
Definition king8Info.h:46
static const King8Info make(NumEffectState const &state, Square king)
unsigned int libertyCandidate() const
16-23 bit 目を 0-7bitにshiftして返す
Definition king8Info.h:64
unsigned int liberty() const
8-15 bit 目を 0-7bitにshiftして返す
Definition king8Info.h:54
unsigned int countMoveCandidate(NumEffectState const &state) const
Definition king8Info.h:95
unsigned int moveCandidate2() const
24-31 bit 目を 0-7bitにshiftして返す
Definition king8Info.h:69
static const King8Info makeWithPin(Player attack, NumEffectState const &state, const PieceMask &pinned)
alt(attack) のking について計算.
Definition king8Info.cc:159
unsigned int moveCandidateMask(NumEffectState const &state) const
Definition king8Info.h:114
unsigned int libertyDropMask() const
0-15bit
Definition king8Info.h:59
unsigned int dropCandidate() const
0-7 bit 目を返す
Definition king8Info.h:49
bool hasMoveCandidate(NumEffectState const &state) const
Definition king8Info.h:128
static const King8Info make(NumEffectState const &state, Square king, PieceMask pinned)
unsigned int libertyCount() const
libertyの数
Definition king8Info.h:82
unsigned int moves() const
Definition king8Info.h:77
static uint64_t hasEffectMask(NumEffectState const &state, Square target, PieceMask pinned, PieceMask on_board_defense)
alt(P)の玉にDirの方向で迫るcanMoveMaskを計算する.
Definition king8Info.cc:67
unsigned int countMoveCandidate(Player player, NumEffectState const &state) const
Definition king8Info.h:108
unsigned int moveCandidateDir(NumEffectState const &state, Square target) const
Definition king8Info.h:87
unsigned int spaces() const
Definition king8Info.h:73
std::ostream & operator<<(std::ostream &, King8Info)
Definition king8Info.cc:10
Player
Definition basic_type.h:8
@ BLACK
Definition basic_type.h:9
const PtypeO PTYPEO_EDGE __attribute__((unused))
constexpr Player alt(Player player)
Definition basic_type.h:13
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか. 相手の影利きが先にある場合は対象としない.