00001 #ifndef OSL_MOVE_GENERATOR_ESCAPE_H
00002 #define OSL_MOVE_GENERATOR_ESCAPE_H
00003 #include "osl/move_generator/pieceOnBoard.h"
00004 #include "osl/move_generator/capture_.h"
00005 #include "osl/move_generator/move_action.h"
00006 #include "osl/basic_type.h"
00007
00008 namespace osl
00009 {
00010 namespace move_generator
00011 {
00016 template<class Action>
00017 class Escape
00018 {
00019 public:
00026 template<Player P,bool CheapOnly>
00027 static void generateBlocking(const NumEffectState& state,Piece p,Square to,Square from,Action &action);
00034 template<Player P,bool CheapOnly>
00035 static void generateBlockingKing(const NumEffectState& state,Piece p,Square from,Action &action);
00041 template<Player P>
00042 static void generateCaptureKing(const NumEffectState& state,Piece p,Square target,Action& action) {
00043 Capture<Action>::template escapeByCapture<P>(state,target,p,action);
00044 }
00045 template<Player P>
00046 static void generateCapture(const NumEffectState& state,Piece p,Square target,Action& action) {
00047 Capture<Action>::template escapeByCapture<P>(state,target,p,action);
00048 }
00049 template<Player P,Ptype Type>
00050 static void generateEscape(const NumEffectState& state,Piece p,Action& action,Int2Type<Type>);
00051
00055 template<Player P,Ptype Type>
00056 static void generateEscape(const NumEffectState& state,Piece p,Action& action){
00060 if(Type==KING){
00061 assert(p.owner()==P && p.ptype()==KING);
00062 PieceOnBoard<Action>::template
00063 generatePtype<P,Type>(state,p,action);
00064 }
00065 else
00066 {
00067 typedef move_action::NoEffectFilter<P,Action> CheckAction;
00068 CheckAction checkAction(state,action,p.square());
00069 PieceOnBoard<CheckAction>::template
00070 generatePtype<P,Type>(state,p,
00071 checkAction);
00072 }
00073 }
00074
00075 public:
00076 template<Player P,bool cheapOnly>
00077 static void generateKingEscape(const NumEffectState& state,Action& action);
00078
00082 template<Player P,Ptype Type,bool CheapOnly>
00083 static void generateMovesBy(const NumEffectState& state,Piece p,Piece attacker,Action& action);
00084 template<Player P,Ptype Type,bool CheapOnly>
00085 static void generateMovesBy(const NumEffectState& state,Piece p,Move last_move,Action& action);
00086 template<Player P,Ptype Type,bool CheapOnly>
00087 static void generateMovesBy(const NumEffectState& state,Piece p,Action& action);
00088
00093 template<Player P,bool CheapOnly>
00094 static void generateMoves(const NumEffectState& state,Piece piece,Piece attacker,Action& action);
00095
00099 template<Player P,bool shouldPromote,bool CheapOnly>
00100 static void generate(const NumEffectState& state,Piece piece,Action& action);
00101 };
00102
00103 template <Player P>
00104 struct GenerateEscape
00105 {
00106 template <class Action>
00107 static void generate(const NumEffectState& state, Piece piece, Action& a)
00108 {
00109 Escape<Action>::template generate<P,true,false>(state, piece, a);
00110 }
00111 static void generate(const NumEffectState& state, Piece piece, MoveVector& out)
00112 {
00113 move_action::Store store(out);
00114 Escape<move_action::Store>::template generate<P,true,false>(state, piece, store);
00115 }
00116 template <class Action>
00117 static void generateCheap(const NumEffectState& state, Piece piece, Action& a)
00118 {
00119 Escape<Action>::template generate<P,true,true>(state, piece, a);
00120 }
00121
00122 static void generateCheap(const NumEffectState& state, Piece piece, MoveVector& out)
00123 {
00124 move_action::Store store(out);
00125 Escape<move_action::Store>::template generate<P,true,false>(state, piece, store);
00126 }
00127
00129 template <size_t Capacity>
00130 static void generateKingEscape(const NumEffectState& state, FixedCapacityVector<Move,Capacity>& out)
00131 {
00132 move_action::Store store(out);
00133 Escape<move_action::Store>::generateKingEscape<P,false>(state, store);
00134 }
00135 template <size_t Capacity>
00136 static void generateCheapKingEscape(const NumEffectState& state, FixedCapacityVector<Move,Capacity>& out)
00137 {
00138 move_action::Store store(out);
00139 Escape<move_action::Store>::generateKingEscape<P,true>(state, store);
00140 }
00141 };
00142 struct GenerateEscapeOfTurn
00143 {
00144 template <class Action>
00145 static void generate(const NumEffectState& state, Piece piece, Action& a)
00146 {
00147 if (state.turn() == BLACK)
00148 {
00149 Escape<Action>::template generate<BLACK,true,false>(state, piece, a);
00150 }
00151 else
00152 {
00153 Escape<Action>::template generate<WHITE,true,false>(state, piece, a);
00154 }
00155 }
00156 };
00157
00158 }
00159 struct GenerateEscapeKing
00160 {
00162 static void generate(const NumEffectState& state, MoveVector& out);
00163 static void generateCheap(const NumEffectState& state, MoveVector& out);
00164 };
00165 using move_generator::GenerateEscape;
00166 }
00167 #endif // OSL_MOVE_GENERATOR_ESCAPE_H
00168
00169
00170
00171