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 State,class Action>
00018 class AlwaysMove
00019 {
00020 BOOST_CLASS_REQUIRE(Action,osl::move_action,Concept);
00021 private:
00022 const State& state;
00023 Action& ac;
00024 public:
00025 AlwaysMove(const State& s, Action & a) : state(s), ac(a) {}
00029 template<Player P,Ptype Type>
00030 void doActionPtype(Piece p1,Position to){
00031 Position from=p1.position();
00032 if (canPromote(Type) &&
00033 !p1.isPromotedNotKingGold() &&
00034 (to.canPromote<P>() || from.canPromote<P>())){
00035 ac.unknownMove(from,to,state.getPieceAt(to),promote(Type),true,P);
00036 }
00037 if (!canPromote(Type) ||
00038 PtypePlayerTraits<Type,P>::canDropTo(to) ||
00039 p1.isPromotedNotKingGold()){
00040 ac.unknownMove(from,to,state.getPieceAt(to),p1.ptype(),false,P);
00041 }
00042 }
00046 template<Player P>
00047 void doAction(Piece p1,Position to)
00048 {
00049 Position from=p1.position();
00050 Ptype ptype=p1.ptype();
00051 if(canPromote(ptype))
00052 {
00053 if (to.canPromote<P>())
00054 {
00055 ac.unknownMove(from,to,state.getPieceAt(to),promote(ptype),true,P);
00056 if(Ptype_Table.canDropTo(P, ptype,to))
00057 {
00058 ac.unknownMove(from,to,state.getPieceAt(to),ptype,false,P);
00059 }
00060 }
00061 else if (from.canPromote<P>())
00062 {
00063 ac.unknownMove(from,to,state.getPieceAt(to),promote(ptype),true,P);
00064 ac.unknownMove(from,to,state.getPieceAt(to),ptype,false,P);
00065 }
00066 else
00067 {
00068 ac.unknownMove(from,to,state.getPieceAt(to),ptype,false,P);
00069 }
00070 }
00071 else
00072 {
00073 ac.unknownMove(from,to,state.getPieceAt(to),ptype,false,P);
00074 }
00075 }
00076 bool done() const{ return false; }
00077 };
00078 }
00079 }
00080 #endif // _ALWAYS_MOVE_ACTION
00081
00082
00083
00084