1 #ifndef _GENERATE_PIECE_MOVES_TCC
2 #define _GENERATE_PIECE_MOVES_TCC
11 namespace move_generator
13 namespace piece_on_board
22 template <Player P,
class Action,PromoteType CanP,Direction Dir,
bool notPromoteCapture>
29 const Piece *limitPtr=state.getPiecePtr(limit);
32 assert(!offset.
zero());
40 for(
int i=0;i<
count;i++){
43 if(!notPromoteCapture && p1.
canMoveOn<P>())
44 action.unknownMove(from,to,p1,ptype,
false,P,m.
newAddCapture(p1));
47 action.simpleMove(from,to,ptype,
false,P,m);
52 if(notPromoteCapture)
return;
56 ptr+=offset.intValue();
69 action.simpleMove(from,to,ptype,
false,P,m);
70 ptr+=offset.intValue();
73 if(notPromoteCapture)
return;
77 action.unknownMove(from,to,p1,ptype,
false,P,m);
81 template <Player P,
class Action,PromoteType CanP,Direction Dir,
bool notPromoteCapture>
87 template <Player P,Ptype T,
class Action,PromoteType CanP,Direction Dir,
bool notPromoteCapture>
93 Dir,notPromoteCapture>(state,p,ptr,pos,action,
102 template <Player P,
class Action,PromoteType CanP,Direction Dir,
bool notPromoteCapture>
114 action.unknownMove(from,to,p1,ptype,
false,P,m);
118 template <Player P,
class Action,PromoteType CanP,Direction Dir,
bool notPromoteCapture>
124 template <Player P,Ptype T,
class Action,PromoteType CanP,Direction Dir,
bool notPromoteCapture>
130 Dir,notPromoteCapture>(ptr,from,action,
135 template <Player P,Ptype T,
class Action,PromoteType CanP,
bool useDirMask,
bool notPromoteCapture>
141 const Piece *ptr=state.getPiecePtr(from);
142 if(!useDirMask || (dirMask&(1<<
UL))==0){
143 generateShort<P,T,Action,CanP,UL,notPromoteCapture>(ptr,from,action,moveBase,ptype);
144 generateShort<P,T,Action,CanP,DR,notPromoteCapture>(ptr,from,action,moveBase,ptype);
145 generateLong<P,T,Action,CanP,LONG_UL,notPromoteCapture>(state,p,ptr,from,action,moveBase,ptype);
146 generateLong<P,T,Action,CanP,LONG_DR,notPromoteCapture>(state,p,ptr,from,action,moveBase,ptype);
148 if(!useDirMask || (dirMask&(1<<
UR))==0){
149 generateShort<P,T,Action,CanP,UR,notPromoteCapture>(ptr,from,action,moveBase,ptype);
150 generateShort<P,T,Action,CanP,DL,notPromoteCapture>(ptr,from,action,moveBase,ptype);
151 generateLong<P,T,Action,CanP,LONG_UR,notPromoteCapture>(state,p,ptr,from,action,moveBase,ptype);
152 generateLong<P,T,Action,CanP,LONG_DL,notPromoteCapture>(state,p,ptr,from,action,moveBase,ptype);
154 if(!useDirMask || (dirMask&(1<<
U))==0){
155 generateShort<P,T,Action,CanP,U,notPromoteCapture>(ptr,from,action,moveBase,ptype);
156 generateShort<P,T,Action,CanP,D,notPromoteCapture>(ptr,from,action,moveBase,ptype);
157 generateLong<P,T,Action,CanP,LONG_U,notPromoteCapture>(state,p,ptr,from,action,moveBase,ptype);
158 generateLong<P,T,Action,CanP,LONG_D,notPromoteCapture>(state,p,ptr,from,action,moveBase,ptype);
160 if(!useDirMask || (dirMask&(1<<
L))==0){
161 generateShort<P,T,Action,CanP,L,notPromoteCapture>(ptr,from,action,moveBase,ptype);
162 generateShort<P,T,Action,CanP,R,notPromoteCapture>(ptr,from,action,moveBase,ptype);
163 generateLong<P,T,Action,CanP,LONG_L,notPromoteCapture>(state,p,ptr,from,action,moveBase,ptype);
164 generateLong<P,T,Action,CanP,LONG_R,notPromoteCapture>(state,p,ptr,from,action,moveBase,ptype);
166 generateShort<P,T,Action,CanP,UUL,notPromoteCapture>(ptr,from,action,moveBase,ptype);
167 generateShort<P,T,Action,CanP,UUR,notPromoteCapture>(ptr,from,action,moveBase,ptype);
170 template <Player P,Direction Dir,
class Action,
bool notPromoteCapture>
174 if((liberty&(1<<Dir))!=0){
178 Piece p1=ptr[offset.intValue()];
180 if(notPromoteCapture && !p1.
isEmpty())
return;
182 action.unknownMove(from,to,p1,
KING,
false,P,m);
186 template <Player P,
class Action,
bool useDirMask,
bool notPromoteCapture>
190 King8Info king8info(state.Iking8Info(P));
191 unsigned int liberty=king8info.
liberty();
193 const Piece *ptr=state.getPiecePtr(pos);
194 if(!useDirMask || (dirMask&(1<<
UL))==0){
195 generateKingDir<P,UL,Action,notPromoteCapture>(ptr,pos,action,liberty,moveBase);
196 generateKingDir<P,DR,Action,notPromoteCapture>(ptr,pos,action,liberty,moveBase);
198 if(!useDirMask || (dirMask&(1<<
U))==0){
199 generateKingDir<P,U,Action,notPromoteCapture>(ptr,pos,action,liberty,moveBase);
200 generateKingDir<P,D,Action,notPromoteCapture>(ptr,pos,action,liberty,moveBase);
202 if(!useDirMask || (dirMask&(1<<
UR))==0){
203 generateKingDir<P,UR,Action,notPromoteCapture>(ptr,pos,action,liberty,moveBase);
204 generateKingDir<P,DL,Action,notPromoteCapture>(ptr,pos,action,liberty,moveBase);
206 if(!useDirMask || (dirMask&(1<<
L))==0){
207 generateKingDir<P,L,Action,notPromoteCapture>(ptr,pos,action,liberty,moveBase);
208 generateKingDir<P,R,Action,notPromoteCapture>(ptr,pos,action,liberty,moveBase);
212 template <Player P,
class Action,
bool useDirMask,
bool notPromoteCapture>
216 if(!useDirMask || (dirMask&(1<<
U))==0){
220 Piece p1=state.pieceAt(to);
221 int limity=(P==
BLACK ? to.
y() : 10-to.
y());
222 int fromy=(P==
BLACK ? from.
y() : 10-from.
y());
223 int ycount=fromy-limity-1;
226 case 4:
case 5:
case 6:
case 7:
case 8:
case 9:{
227 if(!notPromoteCapture && p1.
canMoveOn<P>())
233 if(!notPromoteCapture && p1.
canMoveOn<P>()){
236 action.unknownMove(from,to,p1,
LANCE,
false,P,m1);
241 if(!notPromoteCapture && p1.
canMoveOn<P>()){
251 if(!notPromoteCapture)
255 if(!notPromoteCapture && p1.
canMoveOn<P>()){
262 if(!notPromoteCapture)
271 if(!notPromoteCapture)
275 if(!notPromoteCapture)
277 action.simpleMove(from,to,
LANCE,
false,P,m);
281 action.simpleMove(from,to,
LANCE,
false,P,m);
289 template <Player P,
class Action,
bool useDirMask,
bool notPromoteCapture>
293 assert(from == p.
square());
294 if(!useDirMask || (dirMask&(1<<
U))==0){
295 if(notPromoteCapture && (P==
BLACK ? from.
yLe<4>() : from.
yGe<6>()))
return;
298 Piece p1=state.pieceAt(to);
299 if(notPromoteCapture){
301 action.simpleMove(from,to,
PAWN,
false,P);
306 if(notPromoteCapture)
return;
308 action.unknownMove(from,to,p1,
PPAWN,
true,P,
319 template <
class Action,
bool notPromoteCapture>
320 template <Player P,Ptype T,
bool useDirMask>
330 generateKing<P,Action,useDirMask,notPromoteCapture>(state,action,from,dirMask);
333 generateLance<P,Action,useDirMask,notPromoteCapture>(state,p,action,from,dirMask);
336 generatePawn<P,Action,useDirMask,notPromoteCapture>(state,p,action,from,dirMask);
340 generatePtypePromote<P,T,Action,MustPromoteType,useDirMask,notPromoteCapture>(state,p,action,from,dirMask);
342 generatePtypePromote<P,T,Action,CanPromoteType,useDirMask,notPromoteCapture>(state,p,action,from,dirMask);
344 generatePtypePromote<P,T,Action,CheckPromoteType,useDirMask,notPromoteCapture>(state,p,action,from,dirMask);
346 generatePtypePromote<P,T,Action,NoPromoteType,useDirMask,notPromoteCapture>(state,p,action,from,dirMask);
349 generatePtypePromote<P,T,Action,NoPromoteType,useDirMask,notPromoteCapture>(state,p,action,from,dirMask);
352 template <
class Action,
bool notPromoteCapture>
353 template <Player P,Ptype T,
bool useDirMask>
359 if(state.pin(P).test(num)){
364 generatePtypeUnsafe<P,T,true>(state,p,action,dirMask);
367 generatePtypeUnsafe<P,T,useDirMask>(state,p,action,dirMask);
370 template <
class Action,
bool notPromoteCapture>
371 template <Player P,
bool useDirmask>
378 generatePtype<P,GOLD,useDirmask>(state,p,action,dirMask);
break;
380 generatePtype<P,PAWN,useDirmask>(state,p,action,dirMask);
break;
382 generatePtype<P,LANCE,useDirmask>(state,p,action,dirMask);
break;
384 generatePtype<P,KNIGHT,useDirmask>(state,p,action,dirMask);
break;
386 generatePtype<P,SILVER,useDirmask>(state,p,action,dirMask);
break;
388 generatePtype<P,BISHOP,useDirmask>(state,p,action,dirMask);
break;
390 generatePtype<P,PBISHOP,useDirmask>(state,p,action,dirMask);
break;
392 generatePtype<P,ROOK,useDirmask>(state,p,action,dirMask);
break;
394 generatePtype<P,PROOK,useDirmask>(state,p,action,dirMask);
break;
396 generatePtype<P,KING,useDirmask>(state,p,action,dirMask);
break;