00001
00002
00003 #ifndef MOBILITY_BISHOP_MOBILITY_H
00004 #define MOBILITY_BISHOP_MOBILITY_H
00005 #include "osl/mobility/countMobility.h"
00006
00007 namespace osl
00008 {
00009 namespace mobility
00010 {
00014 struct BishopMobility
00015 {
00016 public:
00024 template<Player P>
00025 static void countBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
00026 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
00027 assert(p.isOnBoard());
00028 assert(p.owner()==P);
00029 const Square pos=p.square();
00030 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<UL,P>::offset(),countAll,countSafe);
00031 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<UR,P>::offset(),countAll,countSafe);
00032 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<DL,P>::offset(),countAll,countSafe);
00033 countMobilityBoth<P,true,true>(state,pos,DirectionPlayerTraits<DR,P>::offset(),countAll,countSafe);
00034 }
00035 static void countBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
00036 if(pl==BLACK)
00037 countBoth<BLACK>(state,p,countAll,countSafe);
00038 else
00039 countBoth<WHITE>(state,p,countAll,countSafe);
00040 }
00044 template<Player P>
00045 static int countAll(const NumEffectState& state,int num){
00046 const Square posUL=state.mobilityOf(UL,num);
00047 const Square posUR=state.mobilityOf(UR,num);
00048 const Square posDL=state.mobilityOf(DL,num);
00049 const Square posDR=state.mobilityOf(DR,num);
00050 int count=posDR.y()-posUL.y()+
00051 posDL.y()-posUR.y()-4+
00052 (state.pieceAt(posUR).template canMoveOn<P>() ? 1 : 0)+
00053 (state.pieceAt(posDR).template canMoveOn<P>() ? 1 : 0)+
00054 (state.pieceAt(posUL).template canMoveOn<P>() ? 1 : 0)+
00055 (state.pieceAt(posDL).template canMoveOn<P>() ? 1 : 0);
00056 return count;
00057 }
00058 template<Player P>
00059 static int countAll(const NumEffectState& state,Piece p){
00060 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
00061 assert(p.isOnBoard());
00062 assert(p.owner()==P);
00063 return countAll<P>(state,p.number());
00064 }
00065 static int countAll(Player pl,const NumEffectState& state,Piece p){
00066 if(pl==BLACK)
00067 return countAll<BLACK>(state,p);
00068 else
00069 return countAll<WHITE>(state,p);
00070 }
00071
00072 template<Player P, Direction Dir>
00073 static int countAllDir(const NumEffectState& state,Piece p){
00074 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
00075 assert(p.isOnBoard());
00076 assert(p.owner()==P);
00077 assert(Dir == UL || Dir == UR || Dir == DL || Dir == DR);
00078 Direction dir = (P == BLACK ? Dir : inverse(Dir));
00079 const Square pos = state.mobilityOf(dir, p.number());
00080 int count = std::abs(pos.y() - p.square().y())
00081 - 1 + (state.pieceAt(pos).template canMoveOn<P>() ? 1 : 0);
00082 return count;
00083 }
00084 template <Direction dir>
00085 static int countAllDir(Player pl,const NumEffectState& state,Piece p){
00086 if(pl==BLACK)
00087 return countAllDir<BLACK, dir>(state,p);
00088 else
00089 return countAllDir<WHITE, dir>(state,p);
00090 }
00094 template<Player P>
00095 static int countSafe(const NumEffectState& state,Piece p){
00096 assert(p.ptype()==BISHOP || p.ptype()==PBISHOP);
00097 assert(p.isOnBoard());
00098 assert(p.owner()==P);
00099 const Square pos=p.square();
00100 return
00101 countMobilitySafe(P,state,pos,DirectionPlayerTraits<UL,P>::offset())+
00102 countMobilitySafe(P,state,pos,DirectionPlayerTraits<UR,P>::offset())+
00103 countMobilitySafe(P,state,pos,DirectionPlayerTraits<DL,P>::offset())+
00104 countMobilitySafe(P,state,pos,DirectionPlayerTraits<DR,P>::offset());
00105 }
00106 static int countSafe(Player pl,const NumEffectState& state,Piece p){
00107 if(pl==BLACK)
00108 return countSafe<BLACK>(state,p);
00109 else
00110 return countSafe<WHITE>(state,p);
00111 }
00112 };
00113 }
00114 }
00115 #endif
00116
00117
00118
00119