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_action/noEffectFilter.h"
00006 #include "osl/move_action/concept.h"
00007 #include "osl/move_action/store.h"
00008 #include "osl/container/moveVector.h"
00009 #include "osl/effect/liberty8.h"
00010 #include "osl/move.h"
00011
00012 namespace osl
00013 {
00014 namespace move_generator
00015 {
00020 template<class Action>
00021 class Escape
00022 {
00023
00024 public:
00031 template<Player P,bool CheapOnly>
00032 static void generateBlocking(const NumEffectState& state,Piece p,Square to,Square from,Action &action);
00039 template<Player P,bool CheapOnly>
00040 static void generateBlockingKing(const NumEffectState& state,Piece p,Square from,Action &action);
00046 template<Player P>
00047 static void generateCaptureKing(const NumEffectState& state,Piece p,Square target,Action& action) {
00048 Capture<Action>::template escapeByCapture<P>(state,target,p,action);
00049 }
00050 template<Player P>
00051 static void generateCapture(const NumEffectState& state,Piece p,Square target,Action& action) {
00052 Capture<Action>::template escapeByCapture<P>(state,target,p,action);
00053 }
00054 template<Player P,Ptype Type>
00055 static void generateEscape(const NumEffectState& state,Piece p,Action& action,Int2Type<Type>);
00056
00060 template<Player P,Ptype Type>
00061 static void generateEscape(const NumEffectState& state,Piece p,Action& action){
00065 if(Type==KING){
00066 assert(p.owner()==P && p.ptype()==KING);
00067 PieceOnBoard<Action>::template
00068 generatePtype<P,Type>(state,p,action);
00069 }
00070 else
00071 {
00072 typedef move_action::NoEffectFilter<P,Action> CheckAction;
00073 CheckAction checkAction(state,action,p.square());
00074 PieceOnBoard<CheckAction>::template
00075 generatePtype<P,Type>(state,p,
00076 checkAction);
00077 }
00078 }
00079
00080 public:
00081 template<Player P,bool cheapOnly>
00082 static void generateKingEscape(const NumEffectState& state,Action& action);
00083
00087 template<Player P,Ptype Type,bool CheapOnly>
00088 static void generateMovesBy(const NumEffectState& state,Piece p,Piece attacker,Action& action);
00089 template<Player P,Ptype Type,bool CheapOnly>
00090 static void generateMovesBy(const NumEffectState& state,Piece p,Move last_move,Action& action);
00091 template<Player P,Ptype Type,bool CheapOnly>
00092 static void generateMovesBy(const NumEffectState& state,Piece p,Action& action);
00093
00098 template<Player P,bool CheapOnly>
00099 static void generateMoves(const NumEffectState& state,Piece piece,Piece attacker,Action& action);
00100
00104 template<Player P,bool shouldPromote,bool CheapOnly>
00105 static void generate(const NumEffectState& state,Piece piece,Action& action);
00106 };
00107
00108 template <Player P>
00109 struct GenerateEscape
00110 {
00111 template <class Action>
00112 static void generate(const NumEffectState& state, Piece piece, Action& a)
00113 {
00114 Escape<Action>::template generate<P,true,false>(state, piece, a);
00115 }
00116 static void generate(const NumEffectState& state, Piece piece, MoveVector& out)
00117 {
00118 move_action::Store store(out);
00119 Escape<move_action::Store>::template generate<P,true,false>(state, piece, store);
00120 }
00121 template <class Action>
00122 static void generateCheap(const NumEffectState& state, Piece piece, Action& a)
00123 {
00124 Escape<Action>::template generate<P,true,true>(state, piece, a);
00125 }
00126
00127 static void generateCheap(const NumEffectState& state, Piece piece, MoveVector& out)
00128 {
00129 move_action::Store store(out);
00130 Escape<move_action::Store>::template generate<P,true,false>(state, piece, store);
00131 }
00132
00134 template <size_t Capacity>
00135 static void generateKingEscape(const NumEffectState& state, FixedCapacityVector<Move,Capacity>& out)
00136 {
00137 move_action::Store store(out);
00138 Escape<move_action::Store>::generateKingEscape<P,false>(state, store);
00139 }
00140 template <size_t Capacity>
00141 static void generateCheapKingEscape(const NumEffectState& state, FixedCapacityVector<Move,Capacity>& out)
00142 {
00143 move_action::Store store(out);
00144 Escape<move_action::Store>::generateKingEscape<P,true>(state, store);
00145 }
00146 };
00147 struct GenerateEscapeOfTurn
00148 {
00149 template <class Action>
00150 static void generate(const NumEffectState& state, Piece piece, Action& a)
00151 {
00152 if (state.turn() == BLACK)
00153 {
00154 Escape<Action>::template generate<BLACK,true,false>(state, piece, a);
00155 }
00156 else
00157 {
00158 Escape<Action>::template generate<WHITE,true,false>(state, piece, a);
00159 }
00160 }
00161 };
00162
00163 }
00164 struct GenerateEscapeKing
00165 {
00167 static void generate(const NumEffectState& state, container::MoveVector& out);
00168 static void generateCheap(const NumEffectState& state, container::MoveVector& out);
00169 };
00170 using move_generator::GenerateEscape;
00171 }
00172 #endif // OSL_MOVE_GENERATOR_ESCAPE_H
00173
00174
00175
00176