rookMobility.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rookMobility.h
Go to the documentation of this file.
1 /* rookMobility.h
2 */
3 #ifndef MOBILITY_ROOK_MOBILITY_H
4 #define MOBILITY_ROOK_MOBILITY_H
5 #include "osl/mobility/countMobility.h"
6 #include "osl/boardTable.h"
7
8 namespace osl
9 {
10 namespace mobility
11 {
15 struct RookMobility
16 {
17 public:
25 template<Player P>
26 static void countVerticalBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
27 assert(p.ptype()==ROOK || p.ptype()==PROOK);
28 assert(p.isOnBoard());
29 assert(p.owner()==P);
30 const Square pos=p.square();
31 countMobilityBoth(P,state,pos,DirectionPlayerTraits<U,P>::offset(),countAll,countSafe);
32 countMobilityBoth(P,state,pos,DirectionPlayerTraits<D,P>::offset(),countAll,countSafe);
33 }
34 static void countVerticalBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
35 if(pl==BLACK)
36 countVerticalBoth<BLACK>(state,p,countAll,countSafe);
37 else
38 countVerticalBoth<WHITE>(state,p,countAll,countSafe);
39 }
43 template<Player P>
44 static int countVerticalAll(const NumEffectState& state,int num){
45 // const Square pos=p.square();
46 const Square posU=state.mobilityOf(U,num);
47 const Square posD=state.mobilityOf(D,num);
48 int count=posD.y()-posU.y()-2+
49 (state.pieceAt(posU).template canMoveOn<P>() ? 1 : 0)+
50 (state.pieceAt(posD).template canMoveOn<P>() ? 1 : 0);
51 return count;
52 }
53 template<Player P>
54 static int countVerticalAll(const NumEffectState& state,Piece p){
55 return countVerticalAll<P>(state,p.number());
56 }
57 static int countVerticalAll(Player pl,const NumEffectState& state,Piece p){
58 if(pl==BLACK)
59 return countVerticalAll<BLACK>(state,p);
60 else
61 return countVerticalAll<WHITE>(state,p);
62 }
66 template<Player P>
67 static int countVerticalSafe(const NumEffectState& state,Piece p){
68 const Square pos=p.square();
69 return
70 countMobilitySafe(P,state,pos,DirectionPlayerTraits<U,P>::offset())+
71 countMobilitySafe(P,state,pos,DirectionPlayerTraits<D,P>::offset());
72 }
73 static int countVerticalSafe(Player pl,const NumEffectState& state,Piece p){
74 if(pl==BLACK)
75 return countVerticalSafe<BLACK>(state,p);
76 else
77 return countVerticalSafe<WHITE>(state,p);
78 }
86 template<Player P>
87 static void countHorizontalBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
88 assert(p.ptype()==ROOK || p.ptype()==PROOK);
89 assert(p.isOnBoard());
90 assert(p.owner()==P);
91 const Square pos=p.square();
92 countMobilityBoth(P,state,pos,DirectionPlayerTraits<L,P>::offset(),countAll,countSafe);
93 countMobilityBoth(P,state,pos,DirectionPlayerTraits<R,P>::offset(),countAll,countSafe);
94 }
95 static void countHorizontalBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
96 if(pl==BLACK)
97 countHorizontalBoth<BLACK>(state,p,countAll,countSafe);
98 else
99 countHorizontalBoth<WHITE>(state,p,countAll,countSafe);
100 }
101
102 template<Player P>
103 static int countHorizontalAll(const NumEffectState& state,int num)
104 {
105 const Square posR=state.mobilityOf(R,num);
106 const Square posL=state.mobilityOf(L,num);
107 int count=(posL.x()-posR.x()-2)+
108 (state.pieceAt(posR).template canMoveOn<P>() ? 1 : 0)+
109 (state.pieceAt(posL).template canMoveOn<P>() ? 1 : 0);
110 return count;
111 }
115 template<Player P>
116 static int countHorizontalAll(const NumEffectState& state,Piece p){
117 return countHorizontalAll<P>(state,p.number());
118 }
119 static int countHorizontalAll(Player pl,const NumEffectState& state,Piece p){
120 if(pl==BLACK)
121 return countHorizontalAll<BLACK>(state,p);
122 else
123 return countHorizontalAll<WHITE>(state,p);
124 }
128 template<Player P>
129 static int countHorizontalSafe(const NumEffectState& state,Piece p){
130 const Square pos=p.square();
131 return
132 countMobilitySafe(P,state,pos,DirectionPlayerTraits<L,P>::offset())+
133 countMobilitySafe(P,state,pos,DirectionPlayerTraits<R,P>::offset());
134 }
135 static int countHorizontalSafe(Player pl,const NumEffectState& state,Piece p){
136 if(pl==BLACK)
137 return countHorizontalSafe<BLACK>(state,p);
138 else
139 return countHorizontalSafe<WHITE>(state,p);
140 }
141 };
142 }
143 }
144 #endif /* MOBILITY_ROOK_MOBILITY_H */
145 // ;;; Local Variables:
146 // ;;; mode:c++
147 // ;;; c-basic-offset:2
148 // ;;; End: