lanceMobility.h
Go to the documentation of this file.
00001 /* lanceMobility.h
00002  */
00003 #ifndef MOBILITY_LANCE_MOBILITY_H
00004 #define MOBILITY_LANCE_MOBILITY_H
00005 #include "osl/mobility/countMobility.h"
00006 
00007 namespace osl
00008 {
00009   namespace mobility
00010   {
00014     struct LanceMobility
00015     {
00016     public:
00024       template<Player P>
00025       static void countBoth(const NumEffectState& state,Piece p,int& countAll,int& countSafe){
00026         assert(p.ptype()==LANCE);
00027         assert(p.isOnBoard());
00028         assert(p.owner()==P);
00029         const Square pos=p.square();
00030         countMobilityBoth(P,state,pos,DirectionPlayerTraits<U,P>::offset(),countAll,countSafe);
00031       }
00032       static void countBoth(Player pl,const NumEffectState& state,Piece p,int& countAll,int &countSafe){
00033         if(pl==BLACK)
00034           countBoth<BLACK>(state,p,countAll,countSafe);
00035         else
00036           countBoth<WHITE>(state,p,countAll,countSafe);
00037       }
00041       template<Player P>
00042       static int countAll(const NumEffectState& state,Square pos,int num){
00043         const Square pos1=state.mobilityOf(DirectionPlayerTraits<U,P>::directionByBlack,num);
00044         int count=(P==BLACK ? pos.y()-pos1.y() : pos1.y()- pos.y())-1+
00045           (state.pieceAt(pos1).template canMoveOn<P>() ? 1 : 0);
00046         return count;
00047       }
00048       template<Player P>
00049       static int countAll(const NumEffectState& state,Piece p){
00050         assert(p.ptype()==LANCE);
00051         assert(p.isOnBoard());
00052         assert(p.owner()==P);
00053         return countAll<P>(state,p.square(),p.number());
00054       }
00055       static int countAll(Player pl,const NumEffectState& state,Piece p){
00056         if(pl==BLACK)
00057           return countAll<BLACK>(state,p);
00058         else
00059           return countAll<WHITE>(state,p);
00060       }
00064       template<Player P>
00065       static int countSafe(const NumEffectState& state,Piece p){
00066         assert(p.ptype()==LANCE);
00067         assert(p.isOnBoard());
00068         assert(p.owner()==P);
00069         const Square pos=p.square();
00070         return 
00071           countMobilitySafe(P,state,pos,DirectionPlayerTraits<U,P>::offset());
00072       }
00073       static int countSafe(Player pl,const NumEffectState& state,Piece p){
00074         if(pl==BLACK)
00075           return countSafe<BLACK>(state,p);
00076         else
00077           return countSafe<WHITE>(state,p);
00078       }
00079     };
00080   }
00081 }
00082 #endif /* MOBILITY_LANCE_MOBILITY_H */
00083 // ;;; Local Variables:
00084 // ;;; mode:c++
00085 // ;;; c-basic-offset:2
00086 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines