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/effect_action/simpleMove.h"
00006 #include "osl/effect_action/pieceFilter.h"
00007 #include "osl/move_action/noEffectFilter.h"
00008 #include "osl/move_action/notKingOpenFilter.h"
00009 #include "osl/move_action/concept.h"
00010 #include "osl/effect/liberty8.h"
00011 #include "osl/move.h"
00012
00013
00014
00015 namespace osl
00016 {
00017 namespace container
00018 {
00019 class MoveVector;
00020 }
00021 namespace move_generator
00022 {
00029 template<Player P,class State,class Action>
00030 class Escape
00031 {
00032
00033 typedef move_action::NotKingOpenFilter<P,State,Action> safe_action_t;
00034
00035 public:
00041 static void generateCaptureKing(const State& state,Piece p,Position target,safe_action_t& action) {
00042 Capture<P>::escapeByCapture(state,target,p,action);
00043 }
00044 static void generateCapture(const State& state,Piece p,Position target,Action& action) {
00045 Capture<P>::escapeByCapture(state,target,p,action);
00046 }
00047 template<Ptype Type>
00048 static void generateEscape(const State& state,Piece p,Action& action,Int2Type<Type>);
00052 template<Ptype Type>
00053 static void generateEscape(const State& state,Piece p,Action& action){
00057 #if 1
00058 if(Type==KING){
00059 assert(p.owner()==P && p.ptype()==KING);
00060 Position from=p.position();
00061 effect::Liberty8<P> libertyKing(state,from);
00062 NearMask nearMask=libertyKing.getMask();
00063
00064
00065
00066 while(nearMask.any()){
00067 const int i=nearMask.takeOneBit();
00068 assert(0<=i && i<=7);
00069 Direction dir=static_cast<Direction>(i);
00070 Offset offset=Board_Table.getOffset<P>(dir);
00071
00072
00073 Position to=from-offset;
00074 action.unknownMove(from,to,state.getPieceAt(to),KING,false,P);
00075 }
00076 }
00077 else
00078 #endif
00079 {
00080 typedef move_action::NoEffectFilter<P,State,Action> CheckAction;
00081 CheckAction checkAction(state,action,p.position());
00082 PieceOnBoardType<P,Type>::generate(state,p,checkAction);
00083 }
00084 }
00085
00086 template<Ptype Type>
00087 static void generateDrop(const State& state,Position to,Action& action){
00088 if(state.template hasPieceOnStand<P,Type>()){
00089 if((Type!=PAWN || !state.isPawnMaskSet(P,to.x())) &&
00090 PtypePlayerTraits<Type,P>::canDropTo(to)){
00091 action.dropMove(to,Type,P);
00092 }
00093 }
00094 }
00095
00096 static void generateDropAll(const State& state,Position to,Action& action);
00100 static void generateBlocking(const State& state,Piece p,Position from,Action& action);
00101 static void generateBlockingKing(const State& state,Piece p,Position from,Action& action,safe_action_t& safe_action);
00102 public:
00103 static void generateKingEscape(const State& state,Move last_move,Action& action);
00104
00108 template<Ptype Type>
00109 static void generateMovesBy(const State& state,Piece p,Piece attackerPiece,Action& action);
00110 template<Ptype Type>
00111 static void generateMovesBy(const State& state,Piece p,Move last_move,Action& action);
00112 template<Ptype Type>
00113 static void generateMovesBy(const State& state,Piece p,Action& action);
00114
00124 static void generateMoves(const State& state,Piece piece,Move last_move,Action& action);
00127 static void generateMoves(const State& state,Piece piece,const Piece attackerPiece,Action& action);
00131 static void generateMoves(const State& state,Piece piece,Action& action);
00132 };
00133
00134 template <Player P>
00135 struct GenerateEscape
00136 {
00137 template <class State, class Action>
00138 static void generate(const State& state, Piece piece, Action& a)
00139 {
00140 Escape<P,State,Action>::generateMoves(state, piece, a);
00141 }
00142 };
00143 struct GenerateEscapeOfTurn
00144 {
00145 template <class State, class Action>
00146 static void generate(const State& state, Piece piece, Action& a)
00147 {
00148 if (state.getTurn() == BLACK)
00149 {
00150 Escape<BLACK,State,Action>::generateMoves(state, piece, a);
00151 }
00152 else
00153 {
00154 Escape<WHITE,State,Action>::generateMoves(state, piece, a);
00155 }
00156 }
00157 };
00158
00159 }
00160 struct GenerateEscapeKing
00161 {
00162 template <class State>
00163 static void generate(const State& state, container::MoveVector& out);
00164 };
00165 using move_generator::GenerateEscape;
00166 }
00167 #endif // _GENERATE_ESCAPE_MOVES_H
00168
00169
00170
00171