capture_.tcc
Go to the documentation of this file.
00001 /* generateCaptureMoves.tcc
00002  */
00003 #ifndef _GENERATECAPTUREMOVES_TCC
00004 #define _GENERATECAPTUREMOVES_TCC
00005 
00006 #include "osl/move_generator/capture_.h"
00007 #include "osl/move_generator/pieceOnBoard.h"
00008 #include "osl/effect_action/alwaysMove.h"
00009 #include "osl/effect_action/betterToPromote.h"
00010 #include "osl/player.h"
00011 
00012 namespace osl
00013 {
00014   namespace move_generator
00015   {
00016     using namespace effect_action;
00017     namespace capture
00018     {
00019       template<Player P,class Action>
00020       void generate(const NumEffectState& state,Square target,Action& action,PieceMask pieces)
00021       {
00022         Piece p1=state.pieceAt(target);
00023         while(pieces.any()){
00024           int num=pieces.takeOneBit();
00025           Piece p=state.pieceOf(num);
00026           if(state.pinOrOpen(P).test(num) && !state.pinnedCanMoveTo<P>(p,target))
00027             continue;
00028           PieceOnBoard<Action>::template generatePiece<P>(state,p,target,p1,action);
00029         }
00030       }
00031     }
00032 
00033     template<class Action>
00034     template<Player P>
00035     void Capture<Action>::
00036     generate(const NumEffectState& state,Square target,Action& action)
00037     {
00038       assert(target.isOnBoard());
00039       PieceMask pieces=state.piecesOnBoard(P)&state.effectSetAt(target);
00040       capture::generate<P,Action>(state,target,action,pieces);
00041     }
00042 
00043     template<class Action>
00044     template<Player P>
00045     void Capture<Action>::
00046     escapeByCapture(const NumEffectState& state,Square target,Piece piece,Action& action)
00047     {
00048       PieceMask pieces=state.piecesOnBoard(P)&state.effectSetAt(target);
00049       pieces.reset(piece.number());
00050       capture::generate<P,Action>(state,target,action,pieces);
00051     }
00052 
00053   } // namespace move_generator
00054 } // namespace osl
00055 
00056 template<class Action>
00057 template<osl::Player P>
00058 void osl::move_generator::Capture<Action>::
00059 generate1(const NumEffectState& state,Square target,
00060           Action& action)
00061 {
00062   Piece move = state.findCheapAttackNotBy(P, target, state.pinOrOpen(P));
00063   if (! move.isPiece())
00064     move = state.findCheapAttack(P, target);
00065   if (move.isPiece())
00066     PieceOnBoard<Action>::template generatePiece<P>
00067       (state,move,target,state.pieceAt(target),action);
00068 }
00069 
00070 
00071 #endif /* _GENERATECAPTUREMOVES_TCC */
00072 // ;;; Local Variables:
00073 // ;;; mode:c++
00074 // ;;; c-basic-offset:2
00075 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines