attackToPinned.tcc
Go to the documentation of this file.
00001 #ifndef _MOVE_GENERATOR_ATTACK_TO_PINNED_TCC
00002 #define _MOVE_GENERATOR_ATTACK_TO_PINNED_TCC
00003 #include "osl/move_generator/attackToPinned.h"
00004 #include "osl/ptypeTable.h"
00005 #include "osl/effectContent.h"
00006 #include "osl/move_generator/addEffectWithEffect.h"
00007 #include "osl/misc/loki.h"
00008 using namespace osl;
00009 
00010 namespace osl
00011 {
00012   namespace move_generator
00013   {
00014     namespace {
00015       template<Player P,Ptype T,class Action>
00016       void generatePtype(const NumEffectState& state,Action& action)
00017       {
00018         Square target=state.template kingSquare<PlayerTraits<P>::opponent>();
00019         for(int num=PtypeTraits<T>::indexMin;num<PtypeTraits<T>::indexLimit;num++){
00020           Piece p=state.pieceOf(num);
00021           if(p.template isOnBoardByOwner<P>()){
00022             Square from=p.square();
00023             EffectContent effect=Ptype_Table.getEffect(newPtypeO(P,T),from,target);
00024             if(effect.hasEffect()){
00025               Offset offset=effect.offset();
00026               assert(!offset.zero());
00027               Piece p1;
00028               Square pos=target-offset;
00029               for(;(p1=state.pieceAt(pos)).isEmpty();pos-=offset) ;
00030               if(p1.canMoveOn<P>() &&
00031                  state.hasEffectByPiece(p,pos)){
00032                 AddEffectWithEffect<Action>::template generate<P,false>(state,pos,action);
00033               }
00034             }
00035           }
00036         }
00037       }
00038     }
00039     template<Player P>
00040     template<class Action>
00041     void AttackToPinned<P>::
00042     generate(const NumEffectState& state,Action& action)
00043     {
00044       generatePtype<P,ROOK,Action>(state,action);
00045       generatePtype<P,BISHOP,Action>(state,action);
00046       generatePtype<P,LANCE,Action>(state,action);
00047     }
00048 
00049   }
00050 }
00051 
00052 #endif /* _MOVE_GENERATOR_ATTACK_TO_PINNED_TCC */
00053 // ;;; Local Variables:
00054 // ;;; mode:c++
00055 // ;;; c-basic-offset:2
00056 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines