00001 #ifndef _GENERATE_ESCAPE_MOVES_H
00002 #define _GENERATE_ESCAPE_MOVES_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,Position to,Position from,Action &action);
00039 template<Player P,bool CheapOnly>
00040 static void generateBlockingKing(const NumEffectState& state,Piece p,Position from,Action &action);
00046 template<Player P>
00047 static void generateCaptureKing(const NumEffectState& state,Piece p,Position 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,Position 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.position());
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 attackerPiece,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
00097 template<Player P,bool CheapOnly>
00098 static void generateMoves(const NumEffectState& state,Piece piece,Piece attackerPiece,Action& action);
00099
00103 template<Player P,bool shouldPromote,bool CheapOnly>
00104 static void generate(const NumEffectState& state,Piece piece,Action& action);
00105 };
00106
00107 template <Player P>
00108 struct GenerateEscape
00109 {
00110 template <class Action>
00111 static void generate(const NumEffectState& state, Piece piece, Action& a)
00112 {
00113 Escape<Action>::template generate<P,true,false>(state, piece, a);
00114 }
00115 static void generate(const NumEffectState& state, Piece piece, MoveVector& out)
00116 {
00117 move_action::Store store(out);
00118 Escape<move_action::Store>::template generate<P,true,false>(state, piece, store);
00119 }
00120 template <class Action>
00121 static void generateCheap(const NumEffectState& state, Piece piece, Action& a)
00122 {
00123 Escape<Action>::template generate<P,true,true>(state, piece, a);
00124 }
00125
00126 static void generateCheap(const NumEffectState& state, Piece piece, MoveVector& out)
00127 {
00128 move_action::Store store(out);
00129 Escape<move_action::Store>::template generate<P,true,false>(state, piece, store);
00130 }
00131
00132 template <size_t Capacity>
00133 static void generateKingEscape(const NumEffectState& state, FixedCapacityVector<Move,Capacity>& out)
00134 {
00135 move_action::Store store(out);
00136 Escape<move_action::Store>::generateKingEscape<P,false>(state, store);
00137 }
00138 template <size_t Capacity>
00139 static void generateCheapKingEscape(const NumEffectState& state, FixedCapacityVector<Move,Capacity>& out)
00140 {
00141 move_action::Store store(out);
00142 Escape<move_action::Store>::generateKingEscape<P,true>(state, store);
00143 }
00144 };
00145 struct GenerateEscapeOfTurn
00146 {
00147 template <class Action>
00148 static void generate(const NumEffectState& state, Piece piece, Action& a)
00149 {
00150 if (state.getTurn() == BLACK)
00151 {
00152 Escape<Action>::template generate<BLACK,true,false>(state, piece, a);
00153 }
00154 else
00155 {
00156 Escape<Action>::template generate<WHITE,true,false>(state, piece, a);
00157 }
00158 }
00159 };
00160
00161 }
00162 struct GenerateEscapeKing
00163 {
00164 static void generate(const NumEffectState& state, container::MoveVector& out);
00165 static void generateCheap(const NumEffectState& state, container::MoveVector& out);
00166 };
00167 using move_generator::GenerateEscape;
00168 }
00169 #endif // _GENERATE_ESCAPE_MOVES_H
00170
00171
00172
00173