bishopMobility.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bishopMobility.h
Go to the documentation of this file.
1 /* bishopMobility.h
2 */
3 #ifndef MOBILITY_BISHOP_MOBILITY_H
4 #define MOBILITY_BISHOP_MOBILITY_H
5 #include "osl/mobility/countMobility.h"
6
7 namespace osl
8 {
9 namespace mobility
10 {
14 struct BishopMobility
15 {
16 public:
24 template<Player P>
25 static void countBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
26 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
27 assert(p.isOnBoard());
28 assert(p.owner()==P);
29 const Square pos=p.square();
30 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<UL,P>::offset(),countAll,countSafe);
31 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<UR,P>::offset(),countAll,countSafe);
32 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<DL,P>::offset(),countAll,countSafe);
33 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<DR,P>::offset(),countAll,countSafe);
34 }
35 static void countBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
36 if(pl==BLACK)
37 countBoth<BLACK>(state,p,countAll,countSafe);
38 else
39 countBoth<WHITE>(state,p,countAll,countSafe);
40 }
44 template<Player P>
45 static int countAll(const NumEffectState& state,int num){
46 const Square posUL=state.mobilityOf(UL,num);
47 const Square posUR=state.mobilityOf(UR,num);
48 const Square posDL=state.mobilityOf(DL,num);
49 const Square posDR=state.mobilityOf(DR,num);
50 int count=posDR.y()-posUL.y()+
51 posDL.y()-posUR.y()-4+
52 (state.pieceAt(posUR).template canMoveOn<P>() ? 1 : 0)+
53 (state.pieceAt(posDR).template canMoveOn<P>() ? 1 : 0)+
54 (state.pieceAt(posUL).template canMoveOn<P>() ? 1 : 0)+
55 (state.pieceAt(posDL).template canMoveOn<P>() ? 1 : 0);
56 return count;
57 }
58 template<Player P>
59 static int countAll(const NumEffectState& state,Piece p){
60 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
61 assert(p.isOnBoard());
62 assert(p.owner()==P);
63 return countAll<P>(state,p.number());
64 }
65 static int countAll(Player pl,const NumEffectState& state,Piece p){
66 if(pl==BLACK)
67 return countAll<BLACK>(state,p);
68 else
69 return countAll<WHITE>(state,p);
70 }
71
72 template<Player P, Direction Dir>
73 static int countAllDir(const NumEffectState& state,Piece p){
74 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
75 assert(p.isOnBoard());
76 assert(p.owner()==P);
77 assert(Dir == UL || Dir == UR || Dir == DL || Dir == DR);
78 Direction dir = (P == BLACK ? Dir : inverse(Dir));
79 const Square pos = state.mobilityOf(dir, p.number());
80 int count = std::abs(pos.y() - p.square().y())
81 - 1 + (state.pieceAt(pos).template canMoveOn<P>() ? 1 : 0);
82 return count;
83 }
84 template <Direction dir>
85 static int countAllDir(Player pl,const NumEffectState& state,Piece p){
86 if(pl==BLACK)
87 return countAllDir<BLACK, dir>(state,p);
88 else
89 return countAllDir<WHITE, dir>(state,p);
90 }
94 template<Player P>
95 static int countSafe(const NumEffectState& state,Piece p){
96 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
97 assert(p.isOnBoard());
98 assert(p.owner()==P);
99 const Square pos=p.square();
100 return
101 countMobilitySafe(P,state,pos,DirectionPlayerTraits<UL,P>::offset())+
102 countMobilitySafe(P,state,pos,DirectionPlayerTraits<UR,P>::offset())+
103 countMobilitySafe(P,state,pos,DirectionPlayerTraits<DL,P>::offset())+
104 countMobilitySafe(P,state,pos,DirectionPlayerTraits<DR,P>::offset());
105 }
106 static int countSafe(Player pl,const NumEffectState& state,Piece p){
107 if(pl==BLACK)
108 return countSafe<BLACK>(state,p);
109 else
110 return countSafe<WHITE>(state,p);
111 }
112 };
113 }
114 }
115 #endif /* MOBILITY_BISHOP_MOBILITY_H */
116 // ;;; Local Variables:
117 // ;;; mode:c++
118 // ;;; c-basic-offset:2
119 // ;;; End: