All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
drop.tcc
Go to the documentation of this file.
1 #ifndef _GENERATE_DROP_MOVES_TCC
2 #define _GENERATE_DROP_MOVES_TCC
5 namespace osl
6 {
7  namespace move_generator
8  {
9  namespace drop
10  {
15  template<Player P,class Action,bool hasPawn,bool hasLance,bool hasKnight,int N>
16  void
17  generateX(const NumEffectState& state,Action& action,int x,Move m1,Move m2,Move m3,Ptype t1,Ptype t2,Ptype t3)
18  {
19  assert(hasPawn || hasLance || hasKnight || N>0);
20  if(P==BLACK){
21  if(N>0){
22  Square pos(x,1);
23  Piece p=state.pieceAt(pos);
24  if(p.isEmpty()){
25  if(N==4){
26  action.dropMove(pos,ROOK,P);
27  action.dropMove(pos,BISHOP,P);
28  action.dropMove(pos,GOLD,P);
29  action.dropMove(pos,SILVER,P);
30  }
31  else{
32  if(N>=1) action.dropMove(pos,t1,P,m1.newAddTo(pos));
33  if(N>=2) action.dropMove(pos,t2,P,m2.newAddTo(pos));
34  if(N>=3) action.dropMove(pos,t3,P,m3.newAddTo(pos));
35  }
36  }
37  }
38  if(hasPawn || hasLance || N>0){
39  Square pos(x,2);
40  Piece p=state.pieceAt(pos);
41  if(p.isEmpty()){
42  if(N==4){
43  action.dropMove(pos,ROOK,P);
44  action.dropMove(pos,BISHOP,P);
45  action.dropMove(pos,GOLD,P);
46  action.dropMove(pos,SILVER,P);
47  }
48  else{
49  if(N>=1) action.dropMove(pos,t1,P,m1.newAddTo(pos));
50  if(N>=2) action.dropMove(pos,t2,P,m2.newAddTo(pos));
51  if(N>=3) action.dropMove(pos,t3,P,m3.newAddTo(pos));
52  }
53  if(hasLance)
54  action.dropMove(pos,LANCE,P);
55  if(hasPawn)
56  action.dropMove(pos,PAWN,P);
57  }
58  }
59  for(int y=3;y<=9;y++){
60  Square pos(x,y);
61  Piece p=state.pieceAt(pos);
62  if(p.isEmpty()){
63  if(N==4){
64  action.dropMove(pos,ROOK,P);
65  action.dropMove(pos,BISHOP,P);
66  action.dropMove(pos,GOLD,P);
67  action.dropMove(pos,SILVER,P);
68  }
69  else{
70  if(N>=1) action.dropMove(pos,t1,P,m1.newAddTo(pos));
71  if(N>=2) action.dropMove(pos,t2,P,m2.newAddTo(pos));
72  if(N>=3) action.dropMove(pos,t3,P,m3.newAddTo(pos));
73  }
74  if(hasKnight)
75  action.dropMove(pos,KNIGHT,P);
76  if(hasLance)
77  action.dropMove(pos,LANCE,P);
78  if(hasPawn)
79  action.dropMove(pos,PAWN,P);
80  }
81  }
82  }
83  else{
84  if(N>0){
85  Square pos(x,9);
86  Piece p=state.pieceAt(pos);
87  if(p.isEmpty()){
88  if(N==4){
89  action.dropMove(pos,ROOK,P);
90  action.dropMove(pos,BISHOP,P);
91  action.dropMove(pos,GOLD,P);
92  action.dropMove(pos,SILVER,P);
93  }
94  else{
95  if(N>=1) action.dropMove(pos,t1,P,m1.newAddTo(pos));
96  if(N>=2) action.dropMove(pos,t2,P,m2.newAddTo(pos));
97  if(N>=3) action.dropMove(pos,t3,P,m3.newAddTo(pos));
98  }
99  }
100  }
101  if(hasPawn || hasLance || N>0){
102  Square pos(x,8);
103  Piece p=state.pieceAt(pos);
104  if(p.isEmpty()){
105  if(N==4){
106  action.dropMove(pos,ROOK,P);
107  action.dropMove(pos,BISHOP,P);
108  action.dropMove(pos,GOLD,P);
109  action.dropMove(pos,SILVER,P);
110  }
111  else{
112  if(N>=1) action.dropMove(pos,t1,P,m1.newAddTo(pos));
113  if(N>=2) action.dropMove(pos,t2,P,m2.newAddTo(pos));
114  if(N>=3) action.dropMove(pos,t3,P,m3.newAddTo(pos));
115  }
116  if(hasLance)
117  action.dropMove(pos,LANCE,P);
118  if(hasPawn)
119  action.dropMove(pos,PAWN,P);
120  }
121  }
122  for(int y=7;y>=1;y--){
123  Square pos(x,y);
124  Piece p=state.pieceAt(pos);
125  if(p.isEmpty()){
126  if(N==4){
127  action.dropMove(pos,ROOK,P);
128  action.dropMove(pos,BISHOP,P);
129  action.dropMove(pos,GOLD,P);
130  action.dropMove(pos,SILVER,P);
131  }
132  else{
133  if(N>=1) action.dropMove(pos,t1,P,m1.newAddTo(pos));
134  if(N>=2) action.dropMove(pos,t2,P,m2.newAddTo(pos));
135  if(N>=3) action.dropMove(pos,t3,P,m3.newAddTo(pos));
136  }
137  if(hasKnight)
138  action.dropMove(pos,KNIGHT,P);
139  if(hasLance)
140  action.dropMove(pos,LANCE,P);
141  if(hasPawn)
142  action.dropMove(pos,PAWN,P);
143  }
144  }
145  }
146  }
147 
148  template<Player P,class Action,bool hasPawn,bool hasLance,bool hasKnight,int N>
149  void
150  generate(const NumEffectState& state,Action& action,Move m1,Move m2,Move m3,Ptype t1,Ptype t2,Ptype t3)
151  {
152  if(hasPawn || hasLance || hasKnight || N>0){
153  if(hasPawn){
154  if(hasLance || hasKnight || N>0){
155  for(int x=9;x>0;x--){
156  if(state.isPawnMaskSet<P>(x))
157  generateX<P,Action,false,hasLance,hasKnight,N>(state,action,x,m1,m2,m3,t1,t2,t3);
158  else
159  generateX<P,Action,true,hasLance,hasKnight,N>(state,action,x,m1,m2,m3,t1,t2,t3);
160  }
161  }
162  else{
163  for(int x=9;x>0;x--){
164  if(!state.isPawnMaskSet<P>(x))
165  generateX<P,Action,true,hasLance,hasKnight,N>(state,action,x,m1,m2,m3,t1,t2,t3);
166  }
167  }
168  }
169  else{ // pawnなし
170  for(int x=9;x>0;x--){
171  generateX<P,Action,false,hasLance,hasKnight,N>(state,action,x,m1,m2,m3,t1,t2,t3);
172  }
173  }
174  }
175  }
176 
177 
178  template<Player P,class Action,bool hasPawn,bool hasLance,bool hasKnight>
179  static void checkSilver(const NumEffectState& state,Action& action)
180  {
181  if(state.template hasPieceOnStand<SILVER>(P)){
182  if(state.template hasPieceOnStand<GOLD>(P)){
183  if(state.template hasPieceOnStand<BISHOP>(P)){
184  if(state.template hasPieceOnStand<ROOK>(P))
185  generate<P,Action,hasPawn,hasLance,hasKnight,4>(
186  state,action,
189  else
190  generate<P,Action,hasPawn,hasLance,hasKnight,3>(
191  state,action,
193  Move(Square::STAND(),GOLD,P),
195  BISHOP,GOLD,SILVER);
196  }
197  else if(state.template hasPieceOnStand<ROOK>(P))
198  generate<P,Action,hasPawn,hasLance,hasKnight,3>(
199  state,action,
200  Move(Square::STAND(),ROOK,P),
201  Move(Square::STAND(),GOLD,P),
203  ROOK,GOLD,SILVER);
204  else
205  generate<P,Action,hasPawn,hasLance,hasKnight,2>(
206  state,action,
207  Move(Square::STAND(),GOLD,P),
209  Move::makeDirect(0),
211  }
212  else if(state.template hasPieceOnStand<BISHOP>(P)){
213  if(state.template hasPieceOnStand<ROOK>(P))
214  generate<P,Action,hasPawn,hasLance,hasKnight,3>(
215  state,action,
216  Move(Square::STAND(),ROOK,P),
219  ROOK,BISHOP,SILVER);
220  else
221  generate<P,Action,hasPawn,hasLance,hasKnight,2>(
222  state,action,
223  Move(Square::STAND(),BISHOP,P),
225  Move::makeDirect(0),
227  }
228  else if(state.template hasPieceOnStand<ROOK>(P))
229  generate<P,Action,hasPawn,hasLance,hasKnight,2>(
230  state,action,
231  Move(Square::STAND(),ROOK,P),
233  Move::makeDirect(0),
235  else
236  generate<P,Action,hasPawn,hasLance,hasKnight,1>(
237  state,action,
238  Move(Square::STAND(),SILVER,P),
239  Move::makeDirect(0),
240  Move::makeDirect(0),
242  }
243  else if(state.template hasPieceOnStand<GOLD>(P)){
244  if(state.template hasPieceOnStand<BISHOP>(P)){
245  if(state.template hasPieceOnStand<ROOK>(P))
246  generate<P,Action,hasPawn,hasLance,hasKnight,3>(
247  state,action,
248  Move(Square::STAND(),ROOK,P),
250  Move(Square::STAND(),GOLD,P),
251  ROOK,BISHOP,GOLD);
252  else
253  generate<P,Action,hasPawn,hasLance,hasKnight,2>(
254  state,action,
255  Move(Square::STAND(),BISHOP,P),
256  Move(Square::STAND(),GOLD,P),
257  Move::makeDirect(0),
259  }
260  else if(state.template hasPieceOnStand<ROOK>(P))
261  generate<P,Action,hasPawn,hasLance,hasKnight,2>(
262  state,action,
263  Move(Square::STAND(),ROOK,P),
264  Move(Square::STAND(),GOLD,P),
265  Move::makeDirect(0),
267  else
268  generate<P,Action,hasPawn,hasLance,hasKnight,1>(
269  state,action,
270  Move(Square::STAND(),GOLD,P),
271  Move::makeDirect(0),
272  Move::makeDirect(0),
274  }
275  else if(state.template hasPieceOnStand<BISHOP>(P)){
276  if(state.template hasPieceOnStand<ROOK>(P))
277  generate<P,Action,hasPawn,hasLance,hasKnight,2>(
278  state,action,
279  Move(Square::STAND(),ROOK,P),
281  Move::makeDirect(0),
283  else
284  generate<P,Action,hasPawn,hasLance,hasKnight,1>(
285  state,action,
286  Move(Square::STAND(),BISHOP,P),
287  Move::makeDirect(0),
288  Move::makeDirect(0),
290  }
291  else if(state.template hasPieceOnStand<ROOK>(P))
292  generate<P,Action,hasPawn,hasLance,hasKnight,1>(
293  state,action,
294  Move(Square::STAND(),ROOK,P),
295  Move::makeDirect(0),
296  Move::makeDirect(0),
298  else
299  generate<P,Action,hasPawn,hasLance,hasKnight,0>(
300  state,action,
301  Move::makeDirect(0),
302  Move::makeDirect(0),
303  Move::makeDirect(0),
305  }
306 
307  template<Player P,class Action,bool hasPawn,bool hasLance>
308  static void checkKnight(const NumEffectState& state,Action& action)
309  {
310  if(state.template hasPieceOnStand<KNIGHT>(P))
311  checkSilver<P,Action,hasPawn,hasLance,true>(state,action);
312  else
313  checkSilver<P,Action,hasPawn,hasLance,false>(state,action);
314  }
315 
316  template<Player P,class Action,bool hasPawn>
317  static void checkLance(const NumEffectState& state,Action& action)
318  {
319  if(state.template hasPieceOnStand<LANCE>(P))
320  checkKnight<P,Action,hasPawn,true>(state,action);
321  else
322  checkKnight<P,Action,hasPawn,false>(state,action);
323  }
324 
325  } // namespace drop
326  using drop::checkLance;
327 
328  template<class Action>
329  template<osl::Player P>
331  generate(const NumEffectState& state,Action& action)
332  {
333  if(state.template hasPieceOnStand<PAWN>(P))
334  checkLance<P,Action,true>(state,action);
335  else
336  checkLance<P,Action,false>(state,action);
337  }
338  } // namespace move_generator
339 } // namespace osl
340 
341 #endif /* _GENERATE_DROP_MOVES_TCC */
342 // ;;; Local Variables:
343 // ;;; mode:c++
344 // ;;; c-basic-offset:2
345 // ;;; End: