All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pieceOnBoard.h
Go to the documentation of this file.
1 #ifndef OSL_PIECE_ON_BOARD_H
2 #define OSL_PIECE_ON_BOARD_H
6 #include <boost/static_assert.hpp>
7 
8 namespace osl
9 {
10  namespace container
11  {
12  class MoveVector;
13  }
14  namespace move_generator
15  {
19  template<class Action,bool noCapturePromote=false>
20  struct PieceOnBoard
21  {
25  template<Player P>
26  static void generatePieceUnsafe(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
27  {
28  assert(state.hasEffectByPiece(p, target));
29  Ptype ptype=p.ptype();
30  Square from=p.square();
31  if(canPromote(ptype)){
32  if(target.canPromote<P>()){
33  action.unknownMove(from,target,p1,promote(ptype),true,P);
34  int y=(P==BLACK ? target.y() : 10-target.y());
35  if(!Ptype_Table.isBetterToPromote(ptype) &&
36  (((ptype==LANCE || ptype==PAWN) ? y==3 : true )) &&
37  Ptype_Table.canDropTo(P,ptype,target))
38  action.unknownMove(from,target,p1,ptype,false,P);
39  }
40  else if(from.canPromote<P>()){
41  action.unknownMove(from,target,p1,promote(ptype),true,P);
42  if(!Ptype_Table.isBetterToPromote(ptype))
43  action.unknownMove(from,target,p1,ptype,false,P);
44  }
45  else
46  action.unknownMove(from,target,p1,ptype,false,P);
47  }
48  else{
49  action.unknownMove(from,target,p1,ptype,false,P);
50  }
51  }
52  template<Player P>
53  static void generatePiece(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
54  {
55  if(p.ptype()==KING){
56  // 王手がかかっているときには自分の影になっている手も生成してしまう
58 // assert(!state.hasEffectAt<altP>(p.square()));
59  // 自殺手
60  if(state.hasEffectAt<altP>(target)) return;
61  }
62  if(state.pinOrOpen(P).test(p.number())){
63  Direction d=state.pinnedDir<P>(p);
65  if(primDir(d)!=primDirUnsafe(d1)) return;
66  }
67  generatePieceUnsafe<P>(state,p,target,p1,action);
68  }
73  template<Player P,Ptype T>
74  static void generatePiecePtypeUnsafe(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
75  {
76  assert(state.hasEffectByPiece(p, target));
77  assert(p.ptype()==T);
78 // Ptype ptype=p.ptype();
79  Square from=p.square();
80  if(canPromote(T) & (target.canPromote<P>() || from.canPromote<P>())){
81  action.unknownMove(from,target,p1,promote(T),true,P);
82  if(((T==PAWN || T==LANCE) &&
83  (P==BLACK ? target.y()==1 : target.y()==9))||
84  (T==KNIGHT && (P==BLACK ? target.y()<=2 : target.y()>=8)))
85  return;
86  if((T==ROOK || T==BISHOP || T==PAWN ||
87  (T==LANCE && (P==BLACK ? target.y()==2 : target.y()==8))))
88  return;
89  }
90  action.unknownMove(from,target,p1,T,false,P);
91  }
92  template<Player P,Ptype T>
93  static void generatePiecePtype(const NumEffectState& state,Piece p, Square target, Piece p1,Action& action)
94  {
95  if(T==KING){
96  assert(!state.hasEffectAt(alt(P),p.square()));
97  if(state.hasEffectAt(alt(P),target)) return;
98  }
99  else if(state.pin(P).test(p.number())){
100  Direction d=state.pinnedDir<P>(p);
102  if(primDir(d)!=primDirUnsafe(d1)) return;
103  }
104  generatePiecePtypeUnsafe<P,T>(state,p,target,p1,action);
105  }
114  template <Player P,Ptype T,bool useDirMask>
115  static void generatePtype(const NumEffectState& state,Piece p, Action& action,int dirMask=0);
116 
117  template <Player P,Ptype T>
118  static void generatePtype(const NumEffectState& state,Piece p, Action& action)
119  {
120  int dummy=0;
121  generatePtype<P,T,false>(state,p,action,dummy);
122  }
131  template <Player P,Ptype T,bool useDirMask>
132  static void generatePtypeUnsafe(const NumEffectState& state,Piece p, Action& action,int dirMask);
133  template <Player P,Ptype T>
134  static void generatePtypeUnsafe(const NumEffectState& state,Piece p, Action& action)
135  {
136  int dummy=0;
137  generatePtypeUnsafe<P,T,false>(state,p,action,dummy);
138  }
139 
147  template <Player P,bool useDirMask>
148  static void generate(const NumEffectState& state,Piece p, Action& action,int dirMask=0);
149  };
150 
152  {
153  static void generate(Player turn, const NumEffectState& state, Piece target,
155  };
156  } // namespace move_generator
158 } // namespace osl
159 
160 #endif /* OSL_PIECE_ON_BOARD_H */
161 // ;;; Local Variables:
162 // ;;; mode:c++
163 // ;;; c-basic-offset:2
164 // ;;; End: