All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
countMobility.h
Go to the documentation of this file.
1 /* countMobility.h
2  */
3 #ifndef MOBILITY_COUNT_MOBILITY_H
4 #define MOBILITY_COUNT_MOBILITY_H
6 
7 namespace osl
8 {
9  namespace mobility
10  {
19  template<Player P,bool All,bool Safe>
20  inline void countMobilityBoth(const NumEffectState& state,Square pos,Offset o,int& countAll,int& countSafe){
21  assert(pos.isOnBoard());
22  assert(!o.zero());
23  Piece p;
24  for(pos+=o;(p=state.pieceAt(pos)).isEmpty();pos+=o){
25  if(All) countAll++;
26  if(Safe && !state.hasEffectAt<PlayerTraits<P>::opponent>(pos))
27  countSafe++;
28  }
29  if(p.canMoveOn<P>()){
30  if(All) countAll++;
31  if(Safe && !state.hasEffectAt<PlayerTraits<P>::opponent>(pos))
32  countSafe++;
33  }
34  }
35  inline void countMobilityBoth(Player P,const NumEffectState& state,Square pos,Offset o,int& countAll,int& countSafe){
36  if(P==BLACK)
37  countMobilityBoth<BLACK,true,true>(state,pos,o,countAll,countSafe);
38  else
39  countMobilityBoth<WHITE,true,true>(state,pos,o,countAll,countSafe);
40  }
44  inline int countMobilityAll(Player pl,const NumEffectState& state,Square pos,Offset o)
45  {
46  int ret=0,dummy=0;
47  if(pl==BLACK)
48  countMobilityBoth<BLACK,true,false>(state,pos,o,ret,dummy);
49  else
50  countMobilityBoth<WHITE,true,false>(state,pos,o,ret,dummy);
51  return ret;
52  }
56  inline int countMobilitySafe(Player pl,const NumEffectState& state,Square pos,Offset o)
57  {
58  int ret=0,dummy=0;
59  if(pl==BLACK)
60  countMobilityBoth<BLACK,false,true>(state,pos,o,dummy,ret);
61  else
62  countMobilityBoth<WHITE,false,true>(state,pos,o,dummy,ret);
63  return ret;
64  }
65  }
66 }
67 #endif /* MOBILITY_ROOK_MOBILITY_H */
68 // ;;; Local Variables:
69 // ;;; mode:c++
70 // ;;; c-basic-offset:2
71 // ;;; End: