My Project
move_action.h
Go to the documentation of this file.
1/* move_action.h
2 */
3#ifndef OSL_MOVEACTION_H
4#define OSL_MOVEACTION_H
7
8namespace osl
9{
10 namespace move_action
11 {
15 struct Store
16 {
18 template <size_t Capacity>
20 : moves(v.pushBackHelper())
21 {
22 }
24 void simpleMove(Square /*from*/,Square /*to*/,Ptype /*ptype*/, bool /*isPromote*/,Player /*p*/,Move move){
25 assert(move.isValid());
26 moves.push_back(move);
27 }
37 void unknownMove(Square /*from*/,Square /*to*/,Piece /*p1*/,Ptype /*ptype*/,bool /*isPromote*/,Player /*p*/,Move move)
38 {
39 assert(move.isValid());
40 moves.push_back(move);
41 }
43 void dropMove(Square /*to*/,Ptype /*ptype*/,Player /*p*/,Move move)
44 {
45 assert(move.isValid());
46 moves.push_back(move);
47 }
48 // old interfaces
49 void simpleMove(Square from,Square to,Ptype ptype,
50 bool isPromote,Player p)
51 {
52 simpleMove(from,to,ptype,isPromote,p,
53 Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
54 }
56 Ptype ptype,bool isPromote,Player p)
57 {
58 unknownMove(from,to,captured,ptype,isPromote,p,
59 Move(from,to,ptype,captured.ptype(),isPromote,p));
60 }
61 void dropMove(Square to,Ptype ptype,Player p)
62 {
63 dropMove(to,ptype,p,
64 Move(to,ptype,p));
65 }
66 };
67
71 template<Player P,class OrigAction>
73 {
75 OrigAction & action;
77 public:
78 NoEffectFilter(const NumEffectState& s, OrigAction & action,Square pos) : state(s), action(action),removed(pos) {}
79 void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player /* p */,Move m){
80 if(!state.template hasEffectByWithRemove<alt(P)>(to,removed))
81 action.simpleMove(from,to,ptype,isPromote,P,m);
82 }
83 void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player /* p */,Move m){
84 if(!state.template hasEffectByWithRemove<alt(P)>(to,removed)){
85 action.unknownMove(from,to,p1,ptype,isPromote,P,m);
86 }
87 }
88 void dropMove(Square to,Ptype ptype,Player /* p */,Move m){
90 if(!state.template hasEffectByWithRemove<alt(P)>(to,removed))
91 action.dropMove(to,ptype,P,m);
92 }
93 // old interfaces
94 void simpleMove(Square from,Square to,Ptype ptype,
95 bool isPromote,Player p)
96 {
97 simpleMove(from,to,ptype,isPromote,p,
98 Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
99 }
101 Ptype ptype,bool isPromote,Player p)
102 {
103 unknownMove(from,to,captured,ptype,isPromote,p,
104 Move(from,to,ptype,captured.ptype(),isPromote,p));
105 }
106 void dropMove(Square to,Ptype ptype,Player p)
107 {
108 dropMove(to,ptype,p,
109 Move(to,ptype,p));
110 }
111 };
112
116 template<class OrigAction>
118 {
120 OrigAction & action;
122 public:
124 void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player p,Move m){
125 if(!state.hasEffectIf(newPtypeO(p,ptype),to,target))
126 action.simpleMove(from,to,ptype,isPromote,p,m);
127 }
128 void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player p,Move m){
129 if(!state.hasEffectIf(newPtypeO(p,ptype),to,target))
130 action.unknownMove(from,to,p1,ptype,isPromote,p,m);
131 }
132 void dropMove(Square to,Ptype ptype,Player p,Move m){
133 if(!state.hasEffectIf(newPtypeO(p,ptype),to,target))
134 action.dropMove(to,ptype,p,m);
135 }
136 // old interfaces
137 void simpleMove(Square from,Square to,Ptype ptype,
138 bool isPromote,Player p)
139 {
140 simpleMove(from,to,ptype,isPromote,p,
141 Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
142 }
144 Ptype ptype,bool isPromote,Player p)
145 {
146 unknownMove(from,to,captured,ptype,isPromote,p,
147 Move(from,to,ptype,captured.ptype(),isPromote,p));
148 }
149 void dropMove(Square to,Ptype ptype,Player p)
150 {
151 dropMove(to,ptype,p,
152 Move(to,ptype,p));
153 }
154 };
155
159 template<Player P,class OrigAction>
161 {
163 OrigAction & action;
164 public:
165 NotKingOpenFilter(const NumEffectState& s, OrigAction & action)
166 : state(s), action(action) {
167 }
169 {
170 return !move_classifier::KingOpenMove<P>::isMember(state, ptype, from, to);
171 }
172 void simpleMove(Square from,Square to,Ptype ptype, bool isPromote,Player
173#ifndef NDEBUG
174 p
175#endif
176 ,Move m
177 ){
178 assert(p == P);
179 if(isNotKingOpenMove(ptype,from,to))
180 action.simpleMove(from,to,ptype,isPromote,P,m);
181
182 }
183 void unknownMove(Square from,Square to,Piece p1,Ptype ptype,bool isPromote,Player
184#ifndef NDEBUG
185 p
186#endif
187 ,Move m
188 ){
189 assert(p == P);
190 if(isNotKingOpenMove(ptype,from,to))
191 action.unknownMove(from,to,p1,ptype,isPromote,P,m);
192 }
197#ifndef NDEBUG
198 p
199#endif
200 ,Move m
201 ){
202 assert(p == P);
203 action.dropMove(to,ptype,P,m);
204 }
205 // old interfaces
206 void simpleMove(Square from,Square to,Ptype ptype,
207 bool isPromote,Player p)
208 {
209 simpleMove(from,to,ptype,isPromote,p,
210 Move(from,to,ptype,PTYPE_EMPTY,isPromote,p));
211 }
213 Ptype ptype,bool isPromote,Player p)
214 {
215 unknownMove(from,to,captured,ptype,isPromote,p,
216 Move(from,to,ptype,captured.ptype(),isPromote,p));
217 }
218 void dropMove(Square to,Ptype ptype,Player p)
219 {
220 dropMove(to,ptype,p,
221 Move(to,ptype,p));
222 }
223 };
224 } // namespace move_action
225} // namespace osl
226
227#endif /* OSL_MOVEACTION_STORE */
228// ;;; Local Variables:
229// ;;; mode:c++
230// ;;; c-basic-offset:2
231// ;;; End:
圧縮していない moveの表現 .
bool isValid() const
利きを持つ局面
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
指定したSquareに利きをつける手をフィルタ
NoAddEffectFilter(const NumEffectState &s, OrigAction &action, Square target)
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p, Move m)
void unknownMove(Square from, Square to, Piece captured, Ptype ptype, bool isPromote, Player p)
void dropMove(Square to, Ptype ptype, Player p)
void unknownMove(Square from, Square to, Piece p1, Ptype ptype, bool isPromote, Player p, Move m)
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p)
void dropMove(Square to, Ptype ptype, Player p, Move m)
利きのないところへ動くためのフィルタ
Definition move_action.h:73
NoEffectFilter(const NumEffectState &s, OrigAction &action, Square pos)
Definition move_action.h:78
void dropMove(Square to, Ptype ptype, Player p)
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:94
void unknownMove(Square from, Square to, Piece captured, Ptype ptype, bool isPromote, Player p)
void unknownMove(Square from, Square to, Piece p1, Ptype ptype, bool isPromote, Player, Move m)
Definition move_action.h:83
void dropMove(Square to, Ptype ptype, Player, Move m)
Definition move_action.h:88
const NumEffectState & state
Definition move_action.h:74
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player, Move m)
Definition move_action.h:79
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
@ PTYPE_EMPTY
Definition basic_type.h:85
Player
Definition basic_type.h:8
constexpr Player alt(Player player)
Definition basic_type.h:13
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
Definition basic_type.h:264
相手の間接利きを止めている駒を動かさない
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p)
NotKingOpenFilter(const NumEffectState &s, OrigAction &action)
bool isNotKingOpenMove(Ptype ptype, Square from, Square to)
void dropMove(Square to, Ptype ptype, Player p)
void unknownMove(Square from, Square to, Piece captured, Ptype ptype, bool isPromote, Player p)
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p, Move m)
void dropMove(Square to, Ptype ptype, Player p, Move m)
dropMoveが自殺手になることはない
void unknownMove(Square from, Square to, Piece p1, Ptype ptype, bool isPromote, Player p, Move m)
指手を MoveVector に保管
Definition move_action.h:16
void dropMove(Square, Ptype, Player, Move move)
コマを打つMove
Definition move_action.h:43
FixedCapacityVectorPushBack< Move > moves
Definition move_action.h:17
Store(FixedCapacityVector< Move, Capacity > &v)
Definition move_action.h:19
void dropMove(Square to, Ptype ptype, Player p)
Definition move_action.h:61
void unknownMove(Square from, Square to, Piece captured, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:55
void unknownMove(Square, Square, Piece, Ptype, bool, Player, Move move)
Definition move_action.h:37
void simpleMove(Square from, Square to, Ptype ptype, bool isPromote, Player p)
Definition move_action.h:49
void simpleMove(Square, Square, Ptype, bool, Player, Move move)
コマをとらないMove
Definition move_action.h:24
static bool isMember(const NumEffectState &state, Ptype, Square from, Square to)
king が59 rookが51->61の時,差は OFFSET -8 -> U OFFSET +8 -> D とはなるので,一直線のような気がする.ただし,そもとも, 59 - 51はpinにはならな...