00001 #ifndef _MOVE_GENERATER_ADD_EFFECT_WITH_EFFECT_H
00002 #define _MOVE_GENERATER_ADD_EFFECT_WITH_EFFECT_H
00003 #include "osl/loki.h"
00004 #include "osl/effect_action/simpleNoPromote.h"
00005 #include "osl/effect_action/noPromote.h"
00006 #include "osl/effect_action/simplePromote.h"
00007 #include "osl/effect_action/promote.h"
00008 #include "osl/effect_action/simpleMove.h"
00009 #include "osl/effect_action/alwaysMove.h"
00010 #include "osl/effect_action/betterToPromote.h"
00011 #include "osl/effect_action/simpleBetterToPromote.h"
00012 #include "osl/move_action/concept.h"
00013 #include <boost/static_assert.hpp>
00014
00015
00016
00017
00018 namespace osl
00019 {
00020 namespace move_generator
00021 {
00022 using namespace effect_action;
00033 template<class State,class Action>
00034 class AddEffectWithEffect
00035 {
00036 BOOST_CLASS_REQUIRE(Action,osl::move_action,Concept);
00037 BOOST_STATIC_ASSERT(sizeof(typename State::effect_state_t));
00038 public:
00043 template<Player P>
00044 static void generateDropSub(const State& state,Position pos,Ptype ptype,Action& action,Int2Type<false>,Int2Type<true>){
00045 }
00046 template<Player P>
00047 static void generateDropSub(const State& state,Position pos,Ptype ptype,Action& action,Int2Type<false>,Int2Type<false>){
00048 }
00049 template<Player P>
00050 static void generateDropSub(const State& state,Position pos,Ptype ptype,Action& action,Int2Type<true>,Int2Type<true>){
00051 if(!state.isPawnMaskSet(P,pos.x()) &&
00052 state.template hasPieceInStand<P,PAWN>())
00053 action.dropMove(pos,PAWN,P);
00054 }
00055 template<Player P>
00056 static void generateDropSub(const State& state,Position pos,Ptype ptype,Action& action,Int2Type<true>,Int2Type<false>){
00057 if(state.hasPieceInStand(P,ptype))
00058 action.dropMove(pos,ptype,P);
00059 }
00060 template<Player P,Direction Dir,Ptype Type>
00061 static void generateDrop(const State& state,Position pos,Action& action){
00062 generateDropSub<P>(state,pos,Type,action,Int2Type<PtypeDirectionTraits<Type,Dir>::canMove>(),Int2Type<Type==PAWN>());
00063 }
00064
00065 template<Player P,Ptype Type,MoveType mt>
00066 static void generateSimpleMovesToSub(const State& state,Position from,Action& action,Int2Type<mt>);
00067
00068 template<Player P,Ptype Type>
00069 static void generateSimpleMovesToSub(const State& state,Position from,Action& action,Int2Type<CannotMove>){
00070 }
00071
00072 template<Player P,Ptype Type>
00073 static void generateSimpleMovesToSub(const State& state,Position from,Action& action,Int2Type<NoConstraint>){
00074 SimpleMove<Action> ac(action);
00075 state.template forEachEffectPtype<P,Type,SimpleMove<Action> >(from,ac);
00076 }
00077
00078 template<Player P,Ptype Type>
00079 static void generateSimpleMovesToSub(const State& state,Position from,Action& action,Int2Type<OnlyPromoted>){
00080 SimplePromote<Action> ac(action);
00081 state.template forEachEffectPtype<P,Type,SimplePromote<Action> >(from,ac);
00082 }
00083
00084 template<Player P,Ptype Type>
00085 static void generateSimpleMovesToSub(const State& state,Position from,Action& action,Int2Type<OnlyBasic>){
00086 SimpleNoPromote<Action> ac(action);
00087 state.template forEachEffectPtype<P,Type,SimpleNoPromote<Action> >(from,ac);
00088 }
00089
00090 template<Player P,Direction Dir,Ptype Type>
00091 static void generateSimpleMovesTo(const State& state,Position from,Action& action);
00092
00093
00094 template<Player P,Ptype Type,MoveType mt>
00095 static void generateCaptureMovesToSub(const State& state,Position from,Action& action,Int2Type<mt>);
00096
00097 template<Player P,Ptype Type>
00098 static void generateCaptureMovesToSub(const State& state,Position from,Action& action,Int2Type<noMove>){
00099 }
00100
00101 template<Player P,Ptype Type>
00102 static void generateCaptureMovesToSub(const State& state,Position from,Action& action,Int2Type<alwaysMove>){
00103 AlwaysMove<State,Action> ac(state, action);
00104 state.template forEachEffectPtype<P,Type,AlwaysMove<State,Action> >(from,ac);
00105 }
00106
00107 template<Player P,Ptype Type>
00108 static void generateCaptureMovesToSub(const State& state,Position from,Action& action,Int2Type<promoteMove>){
00109 Promote<State,Action> ac(state, action);
00110 state.template forEachEffectPtype<P,Type,Promote<State,Action> >(from,ac);
00111 }
00112
00113 template<Player P,Ptype Type>
00114 static void generateCaptureMovesToSub(const State& state,Position from,Action& action,Int2Type<noPromoteMove>){
00115 NoPromote<State,Action> ac(state, action);
00116 state.template forEachEffectPtype<P,Type,NoPromote<State,Action> >(from,ac);
00117 }
00118
00119
00120 template<Player P,Direction Dir,Ptype Type>
00121 static void generateCaptureMovesTo(const State& state,Position from,Action& action);
00122
00124 template<Player P,Direction Dir>
00125 static void generateEffectDir(const State& state,Position pos,Action& action);
00131 template<Player P,Direction Dir>
00132 static void generateEffectDirKnight(const State& state,Position pos,Action & action){
00133 Position pos1=pos-DirectionPlayerTraits<Dir,P>::offset();
00134 Piece p=state.getPieceAt(pos1);
00135 if(p.isEmpty()){
00136
00137 generateDrop<P,Dir,KNIGHT>(state,pos1,action);
00138
00139
00140 SimpleNoPromote<Action> ac(action);
00141 state.template forEachEffectPtype<P,KNIGHT,SimpleNoPromote<Action> >(pos1,ac);
00142 }
00143 else if(canMoveOn<P>(p)){
00144 NoPromote<State,Action> ac(state, action);
00145 state.template forEachEffectPtype<P,KNIGHT,NoPromote<State,Action> >(pos1,ac);
00146 }
00147 }
00148 template<Player P>
00149 static void generateMoves(const State& state,Position pos,Action& action);
00150 static void generateMoves(Player p, const State& state, Position pos, Action& action)
00151 {
00152 if (p == BLACK)
00153 generateMoves<BLACK>(state, pos, action);
00154 else
00155 generateMoves<WHITE>(state, pos, action);
00156 }
00157 };
00158
00159 template<class State,class Action>
00160 template<Player P,Direction Dir,Ptype Type>
00161 inline
00162 void AddEffectWithEffect<State,Action>::generateSimpleMovesTo(const State& state,Position from,Action& action){
00163
00164
00165
00166
00167 generateSimpleMovesToSub<P,Type>(state,from,action,Int2Type<PtypeDirectionTraits<Type,Dir>::moveType >());
00168 }
00169 template<class State,class Action>
00170 template<Player P,Direction Dir,Ptype Type>
00171 inline
00172 void AddEffectWithEffect<State,Action>::generateCaptureMovesTo(const State& state,Position from,Action& action){
00173
00174
00175
00176
00177 generateCaptureMovesToSub<P,Type>
00178 (state,from,action,
00179 Int2Type<PtypeDirectionTraits<Type,Dir>::moveType >());
00180 }
00181
00182 }
00183 }
00184 #endif
00185
00186
00187
00188