00001
00002
00003 #ifndef MOBILITY_ROOK_MOBILITY_H
00004 #define MOBILITY_ROOK_MOBILITY_H
00005 #include "osl/mobility/countMobility.h"
00006 #include "osl/bits/boardTable.h"
00007
00008 namespace osl
00009 {
00010 namespace mobility
00011 {
00015 struct RookMobility
00016 {
00017 public:
00025 template<Player P>
00026 static void countVerticalBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
00027 assert(p.ptype()==ROOK || p.ptype()==PROOK);
00028 assert(p.isOnBoard());
00029 assert(p.owner()==P);
00030 const Square pos=p.square();
00031 countMobilityBoth(P,state,pos,DirectionPlayerTraits<U,P>::offset(),countAll,countSafe);
00032 countMobilityBoth(P,state,pos,DirectionPlayerTraits<D,P>::offset(),countAll,countSafe);
00033 }
00034 static void countVerticalBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
00035 if(pl==BLACK)
00036 countVerticalBoth<BLACK>(state,p,countAll,countSafe);
00037 else
00038 countVerticalBoth<WHITE>(state,p,countAll,countSafe);
00039 }
00043 template<Player P>
00044 static int countVerticalAll(const NumEffectState& state,int num){
00045
00046 const Square posU=state.mobilityOf(U,num);
00047 const Square posD=state.mobilityOf(D,num);
00048 int count=posD.y()-posU.y()-2+
00049 (state.pieceAt(posU).template canMoveOn<P>() ? 1 : 0)+
00050 (state.pieceAt(posD).template canMoveOn<P>() ? 1 : 0);
00051 return count;
00052 }
00053 template<Player P>
00054 static int countVerticalAll(const NumEffectState& state,Piece p){
00055 return countVerticalAll<P>(state,p.number());
00056 }
00057 static int countVerticalAll(Player pl,const NumEffectState& state,Piece p){
00058 if(pl==BLACK)
00059 return countVerticalAll<BLACK>(state,p);
00060 else
00061 return countVerticalAll<WHITE>(state,p);
00062 }
00066 template<Player P>
00067 static int countVerticalSafe(const NumEffectState& state,Piece p){
00068 const Square pos=p.square();
00069 return
00070 countMobilitySafe(P,state,pos,DirectionPlayerTraits<U,P>::offset())+
00071 countMobilitySafe(P,state,pos,DirectionPlayerTraits<D,P>::offset());
00072 }
00073 static int countVerticalSafe(Player pl,const NumEffectState& state,Piece p){
00074 if(pl==BLACK)
00075 return countVerticalSafe<BLACK>(state,p);
00076 else
00077 return countVerticalSafe<WHITE>(state,p);
00078 }
00086 template<Player P>
00087 static void countHorizontalBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
00088 assert(p.ptype()==ROOK || p.ptype()==PROOK);
00089 assert(p.isOnBoard());
00090 assert(p.owner()==P);
00091 const Square pos=p.square();
00092 countMobilityBoth(P,state,pos,DirectionPlayerTraits<L,P>::offset(),countAll,countSafe);
00093 countMobilityBoth(P,state,pos,DirectionPlayerTraits<R,P>::offset(),countAll,countSafe);
00094 }
00095 static void countHorizontalBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int& countSafe){
00096 if(pl==BLACK)
00097 countHorizontalBoth<BLACK>(state,p,countAll,countSafe);
00098 else
00099 countHorizontalBoth<WHITE>(state,p,countAll,countSafe);
00100 }
00101
00102 template<Player P>
00103 static int countHorizontalAll(const NumEffectState& state,int num)
00104 {
00105 const Square posR=state.mobilityOf(R,num);
00106 const Square posL=state.mobilityOf(L,num);
00107 int count=(posL.x()-posR.x()-2)+
00108 (state.pieceAt(posR).template canMoveOn<P>() ? 1 : 0)+
00109 (state.pieceAt(posL).template canMoveOn<P>() ? 1 : 0);
00110 return count;
00111 }
00115 template<Player P>
00116 static int countHorizontalAll(const NumEffectState& state,Piece p){
00117 return countHorizontalAll<P>(state,p.number());
00118 }
00119 static int countHorizontalAll(Player pl,const NumEffectState& state,Piece p){
00120 if(pl==BLACK)
00121 return countHorizontalAll<BLACK>(state,p);
00122 else
00123 return countHorizontalAll<WHITE>(state,p);
00124 }
00128 template<Player P>
00129 static int countHorizontalSafe(const NumEffectState& state,Piece p){
00130 const Square pos=p.square();
00131 return
00132 countMobilitySafe(P,state,pos,DirectionPlayerTraits<L,P>::offset())+
00133 countMobilitySafe(P,state,pos,DirectionPlayerTraits<R,P>::offset());
00134 }
00135 static int countHorizontalSafe(Player pl,const NumEffectState& state,Piece p){
00136 if(pl==BLACK)
00137 return countHorizontalSafe<BLACK>(state,p);
00138 else
00139 return countHorizontalSafe<WHITE>(state,p);
00140 }
00141 };
00142 }
00143 }
00144 #endif
00145
00146
00147
00148