alwaysMove.h
Go to the documentation of this file.
00001 #ifndef _ALWAYS_MOVE_ACTION
00002 #define _ALWAYS_MOVE_ACTION
00003 #include "osl/player.h"
00004 #include "osl/ptype.h"
00005 #include "osl/ptypeTable.h"
00006 #include "osl/ptypeTraits.h"
00007 #include "osl/piece.h"
00008 #include "osl/move_action/concept.h"
00009 
00010 namespace osl
00011 {
00012   namespace effect_action
00013   {
00017     template<class Action>
00018     class AlwaysMove
00019     {
00020       BOOST_CLASS_REQUIRE(Action,osl::move_action,Concept);
00021     private:
00022       const NumEffectState& state;
00023       Action& ac;
00024     public:
00025       AlwaysMove(const NumEffectState& s, Action & a) : state(s), ac(a) {}
00029       template<Player P,Ptype Type>
00030       void doActionPtype(Piece p1,Square to){
00031         assert(Type == unpromote(p1.ptype()));
00032         Square from=p1.square(); 
00033         if (canPromote(Type) &&
00034            !p1.isPromotedNotKingGold() &&
00035            (to.canPromote<P>() || from.canPromote<P>())){
00036           ac.unknownMove(from,to,state.pieceAt(to),promote(Type),true,P);
00037         }
00038         if (!canPromote(Type) ||
00039            PtypePlayerTraits<Type,P>::canDropTo(to) ||
00040            p1.isPromotedNotKingGold()){
00041           ac.unknownMove(from,to,state.pieceAt(to),p1.ptype(),false,P);
00042         }
00043       }
00047       template<Player P>
00048       void doAction(Piece p1,Square to)
00049       {
00050         Square from=p1.square(); 
00051         Ptype ptype=p1.ptype();
00052         if(canPromote(ptype))
00053         {
00054           if (to.canPromote<P>())
00055           {
00056             ac.unknownMove(from,to,state.pieceAt(to),promote(ptype),true,P);
00057             if(Ptype_Table.canDropTo(P, ptype,to))
00058             {
00059               ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
00060             }
00061           }
00062           else if (from.canPromote<P>())
00063           {
00064             ac.unknownMove(from,to,state.pieceAt(to),promote(ptype),true,P);
00065             ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
00066           }
00067           else
00068           {
00069             ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
00070           }
00071         }
00072         else
00073         {
00074           ac.unknownMove(from,to,state.pieceAt(to),ptype,false,P);
00075         }
00076       }
00077       bool done() const{ return false; }
00078     };
00079   } // namespace effect_action
00080 } // namespace osl
00081 #endif // _ALWAYS_MOVE_ACTION
00082 // ;;; Local Variables:
00083 // ;;; mode:c++
00084 // ;;; c-basic-offset:2
00085 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines