1 #ifndef _MOVE_GENERATOR_ADD_EFFECT_TCC
2 #define _MOVE_GENERATOR_ADD_EFFECT_TCC
5 #include "osl/move_action/safeFilter.h"
7 #include <boost/type_traits.hpp>
11 namespace move_generator
13 namespace without_effect
24 template <Player P,Ptype T,
class Action,
bool isPromote>
27 NearMask target_mask =
31 target_mask &= nearMask;
32 while (target_mask.any())
34 const int n =target_mask.takeOneBit();
43 template <Player P,Ptype T,
class Action>
46 assert(state.pieceAt(from).template isOnBoardByOwner<P>());
48 while (target_mask.any())
50 const int n = target_mask.takeOneBit();
56 if (state.hasEffectByPiece(state.pieceAt(from),to))
57 action.unknownMove(from,to,state.pieceAt(to),T,
false,P);
61 template <Player P,Ptype T,
class Action>
64 assert(state.pieceAt(from).template isOnBoardByOwner<P>());
67 while (target_mask.any())
69 const int n = target_mask.takeOneBit();
75 if (state.hasEffectByPiece(state.pieceAt(from),to))
79 if ((target_mask_no_promote.isSet(n))!=0)
80 action.unknownMove(from,to,state.pieceAt(to),T,
false,P);
87 template<
bool isAttackToKing>
92 return state.isEmptyBetween(from,to);
98 for(pos=from+o;pos!=to && (p=state.pieceAt(pos)).isEmpty();pos+=o)
100 if(pos==to)
return true;
103 return state.hasEffectByPiece(p,to);
105 template <Player P,Ptype T,
class Action,
bool canPromote,
bool isAttackToKing>
108 assert(state.pieceAt(from).template isOnBoardByOwner<P>());
127 generateMove<P,T,Action,false>(state,from,
target,nearMask,action);
134 pos1=state.kingMobilityAbs(
alt(P),shortD);
135 if(state.mobilityOf(shortD,piece_num)!=pos1)
return;
136 p=state.pieceAt(pos1);
139 Offset o1=effect_content.
offset().template blackOffset<P>();
142 for(;(p=state.pieceAt(pos1)).isEmpty();pos1-=o1) ;
143 if (pos1==from)
return;
145 if(state.hasEffectByPiece(p,target)){
148 for(pos1-=o1;(p1=state.pieceAt(pos1)).isEmpty();pos1-=o1) ;
155 if (! state.hasEffectByPiece(state.pieceAt(from), pos1))
160 if (! state.hasEffectByPiece(state.pieceAt(from), pos1))
176 (from.canPromote<P>()||pos1.
canPromote<P>()) &&
181 action.unknownMove(from,pos1,p,T,
false,P);
192 generateLongMoveDirectNoPromote<P,T,Action>(state,from,
target,nearMask,action);
196 generateLongMoveDirectCanPromote<P,T,Action>(state,from,
target,nearMask,action);
203 if(isAttackToKing) target_mask&=nearMask;
204 while (target_mask.any())
206 const int n = target_mask.takeOneBit();
210 if (! mid.isOnBoard())
212 Piece p=state.pieceAt(mid);
215 && state.hasEffectByPiece(state.pieceAt(from),mid)
216 && isEmptyOrAdditional<isAttackToKing>(state,mid,target,count))
219 (from.canPromote<P>()||mid.canPromote<P>()))
221 action.unknownMove(from,mid,p,T,
false,P);
229 if(isAttackToKing) target_mask&=nearMask;
230 while (target_mask.any())
232 const int n = target_mask.takeOneBit();
237 if (isEmptyOrAdditional<isAttackToKing>(state,mid,target,count))
239 for(
int i=0;i<2;i++){
240 Piece p=state.pieceAt(mid);
243 (from.canPromote<P>()||mid.canPromote<P>()))
245 action.unknownMove(from,mid,p,T,
false,P);
248 if (isAttackToKing || count>0 || p.
isEdge() || !state.hasEffectByPiece(p,target))
break;
260 if(isAttackToKing) target_mask&=nearMask;
261 while (target_mask.any())
263 const int n = target_mask.takeOneBit();
268 if (isEmptyOrAdditional<isAttackToKing>(state,mid,target,count))
272 Piece p=state.pieceAt(mid);
275 (from.canPromote<P>()||mid.canPromote<P>()))
277 action.unknownMove(from,mid,p,T,
false,P);
280 if (isAttackToKing || count>0 || p.
isEdge() || !state.hasEffectByPiece(p,target))
break;
292 template <Player P,Ptype T,
class Action,
bool isLong,
bool isAttackToKing>
298 if(isAttackToKing &&
isLong) target_mask&=nearMask;
299 while (target_mask.any())
301 const int n = target_mask.takeOneBit();
309 for(pos1=to;(p=state.pieceAt(pos1)).isEmpty();pos1-=offset)
310 action.dropMove(pos1,T,P);
311 if(isAttackToKing || p.
isEdge() || !state.hasEffectByPiece(p,target))
continue;
312 for(pos1-=offset;state.pieceAt(pos1).isEmpty();pos1-=offset)
313 action.dropMove(pos1,T,P);
317 else if (T!=
PAWN || !state.template isPawnMaskSet<P>(to.x()))
318 action.dropMove(to,T,P);
325 template <Player P,Ptype T,
class Action>
349 template <Player P,Ptype T,
class Action>
381 template <Player P,Ptype T,
class Action,
bool isAttackToKing>
419 template <osl::Player P,osl::Ptype T,
bool isAttackToKing>
420 template <
class Action>
427 action_t gkAction(state,target,action,nearMask);
428 state.template forEachOnBoard<P,T,action_t>(gkAction);
430 if (state.template hasPieceOnStand<T>(P))
432 without_effect::generateDrop<P,T,Action,false,isAttackToKing>(state,
target,nearMask,action);
436 template <osl::Player P,osl::Ptype T,
bool isAttackToKing>
437 template <
class Action>
442 action_t gkAction(state,target,action,nearMask);
443 state.template forEachOnBoard<P,T,action_t>(gkAction);
445 if (state.template hasPieceOnStand<T>(P))
447 without_effect::generateDrop<P,T,Action,true,isAttackToKing>(state,
target,nearMask,action);
451 template <osl::Player P,
bool isAttackToKing>
452 template <
class Action>
457 action_t gkAction(state,target,action,nearMask);
458 state.template forEachOnBoard<P,KING,action_t>(gkAction);
461 template <osl::Player P,
bool isAttackToKing>
462 template <
class Action>
467 action_t gkAction(state,target,action,nearMask);
468 state.template forEachOnBoard<P,GOLD,action_t>(gkAction);
470 if (state.template hasPieceOnStand<GOLD>(P))
472 without_effect::generateDrop<P,GOLD,Action,false,isAttackToKing>(state,
target,nearMask,action);
476 template <osl::Player P,
bool isAttackToKing>
477 template <
class Action>
482 NearMask nearMask=NearMask::make<P>(state,
target);
495 template<
bool isAttackToKing>
500 using namespace osl::move_action;
503 SafeFilter<BLACK,Store> filter(state, store);
508 SafeFilter<WHITE,Store> filter(state, store);