00001
00002
00003 #ifndef MOBILITY_COUNT_MOBILITY_H
00004 #define MOBILITY_COUNT_MOBILITY_H
00005 #include "osl/numEffectState.h"
00006
00007 namespace osl
00008 {
00009 namespace mobility
00010 {
00019 template<Player P,bool All,bool Safe>
00020 inline void countMobilityBoth(const NumEffectState& state,Square pos,Offset o,int& countAll,int& countSafe){
00021 assert(pos.isOnBoard());
00022 assert(!o.zero());
00023 Piece p;
00024 for(pos+=o;(p=state.pieceAt(pos)).isEmpty();pos+=o){
00025 if(All) countAll++;
00026 if(Safe && !state.hasEffectAt<alt(P)>(pos))
00027 countSafe++;
00028 }
00029 if(p.canMoveOn<P>()){
00030 if(All) countAll++;
00031 if(Safe && !state.hasEffectAt<alt(P)>(pos))
00032 countSafe++;
00033 }
00034 }
00035 inline void countMobilityBoth(Player P,const NumEffectState& state,Square pos,Offset o,int& countAll,int& countSafe){
00036 if(P==BLACK)
00037 countMobilityBoth<BLACK,true,true>(state,pos,o,countAll,countSafe);
00038 else
00039 countMobilityBoth<WHITE,true,true>(state,pos,o,countAll,countSafe);
00040 }
00044 inline int countMobilityAll(Player pl,const NumEffectState& state,Square pos,Offset o)
00045 {
00046 int ret=0,dummy=0;
00047 if(pl==BLACK)
00048 countMobilityBoth<BLACK,true,false>(state,pos,o,ret,dummy);
00049 else
00050 countMobilityBoth<WHITE,true,false>(state,pos,o,ret,dummy);
00051 return ret;
00052 }
00056 inline int countMobilitySafe(Player pl,const NumEffectState& state,Square pos,Offset o)
00057 {
00058 int ret=0,dummy=0;
00059 if(pl==BLACK)
00060 countMobilityBoth<BLACK,false,true>(state,pos,o,dummy,ret);
00061 else
00062 countMobilityBoth<WHITE,false,true>(state,pos,o,dummy,ret);
00063 return ret;
00064 }
00065 }
00066 }
00067 #endif
00068
00069
00070
00071