00001 #ifndef OSL_BETTER_TO_PROMOTE_MOVE_ACTION_H
00002 #define OSL_BETTER_TO_PROMOTE_MOVE_ACTION_H
00003 #include "osl/move_action/concept.h"
00004 namespace osl
00005 {
00006 namespace effect_action
00007 {
00011 template<class Action>
00012 class BetterToPromote
00013 {
00014 BOOST_CLASS_REQUIRE(Action,osl::move_action,Concept);
00015 private:
00016 const NumEffectState& state;
00017 Action & ac;
00018 public:
00019 BetterToPromote(const NumEffectState& s, Action& a)
00020 : state(s), ac(a)
00021 {
00022 }
00023 template<Player P,Ptype Type>
00024 void doActionPtype(Piece p1,Square to){
00025 assert(Type == unpromote(p1.ptype()));
00026 Square from=p1.square();
00027 Piece target = state.pieceAt(to);
00028 if (canPromote(Type) &&
00029 !p1.isPromotedNotKingGold() &&
00030 (to.canPromote<P>() || from.canPromote<P>())){
00031 ac.unknownMove(from,to,target,promote(Type),true,P);
00032 }
00033 if (!canPromote(Type) ||
00034 PtypePlayerTraits<Type,P>::canDropTo(to) ||
00035 p1.isPromotedNotKingGold()){
00036 if (! (to.canPromote<P>() || from.canPromote<P>())
00037 || (! PtypeTraits<Type>::betterToPromote
00038 && (p1.ptype() != LANCE
00039 || PtypePlayerTraits<LANCE,P>::canDropTo(to + DirectionPlayerTraits<U,P>::offset()))))
00040 ac.unknownMove(from,to,target,p1.ptype(),false,P);
00041 }
00042 }
00046 template<Player P>
00047 void doAction(Piece p1,Square to)
00048 {
00049 Square from=p1.square();
00050 Ptype ptype=p1.ptype();
00051 Piece target = state.pieceAt(to);
00052 if(canPromote(ptype))
00053 {
00054 if (to.canPromote<P>())
00055 {
00056 ac.unknownMove(from,to,target,promote(ptype),true,P);
00057 if(Ptype_Table.canDropTo(P, ptype,to)
00058 && ! Ptype_Table.isBetterToPromote(ptype)
00059 && (ptype != LANCE
00060 || PtypePlayerTraits<LANCE,P>::canDropTo(to + DirectionPlayerTraits<U,P>::offset())))
00061
00062 {
00063 ac.unknownMove(from,to,target,ptype,false,P);
00064 }
00065 return;
00066 }
00067 if (from.canPromote<P>())
00068 {
00069 ac.unknownMove(from,to,target,promote(ptype),true,P);
00070 if(! Ptype_Table.isBetterToPromote(ptype)
00071 && (ptype != LANCE
00072 || PtypePlayerTraits<LANCE,P>::canDropTo(to + DirectionPlayerTraits<U,P>::offset())))
00073 ac.unknownMove(from,to,target,ptype,false,P);
00074 return;
00075 }
00076
00077 }
00078 ac.unknownMove(from,to,target,ptype,false,P);
00079 }
00080 };
00081 }
00082 }
00083 #endif // OSL_BETTER_TO_PROMOTE_MOVE_ACTION_H
00084
00085
00086
00087