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