00001
00002
00003 #ifndef QUIESCENCEGENERATOR_H
00004 #define QUIESCENCEGENERATOR_H
00005
00006 #include "osl/search/shouldPromoteCut.h"
00007 #include "osl/move_generator/addEffect_.h"
00008 #include "osl/move_generator/capture_.h"
00009 #include "osl/move_generator/escape_.h"
00010 #include "osl/move_generator/promote_.h"
00011 #include "osl/move_generator/safeDropMajorPiece.h"
00012 #include "osl/move_generator/addEffect8.h"
00013 #include "osl/move_generator/additionalLance.h"
00014 #include "osl/move_action/store.h"
00015 #include "osl/eval/pieceEval.h"
00016 #include "osl/state/numEffectState.h"
00017 #include "osl/container/position8.h"
00018
00019 namespace osl
00020 {
00021 namespace search
00022 {
00026 template <Player P>
00027 struct QuiescenceGenerator
00028 {
00033 template <Ptype PTYPE, bool has_dont_capture>
00034 static void capture(const NumEffectState&,
00035 MoveVector& moves, Piece dont_capture);
00036 static void captureAll(const NumEffectState&, MoveVector& moves);
00037 static void captureAll(const NumEffectState&,
00038 MoveVector& moves, Piece dont_capture);
00042 static void capture(const NumEffectState&,
00043 Position target, MoveVector& moves);
00044 static void promote(const NumEffectState&, PieceMask pins,
00045 MoveVector& moves);
00046 template <Ptype PTYPE>
00047 static void promote(const NumEffectState&, MoveVector& moves);
00048 static void check(const NumEffectState&, PieceMask pins,
00049 MoveVector& moves, bool no_liberty=false);
00050 static void check(const NumEffectState&, PieceMask pins, bool no_liberty,
00051 const Position8& sendoffs, MoveVector& moves);
00052 static void escapeKing(const NumEffectState& state, MoveVector& moves);
00056 static bool escapeKingInTakeBack(const NumEffectState& state, MoveVector& moves, bool check_by_lance);
00057 static void dropMajorPiece(const NumEffectState& state, MoveVector& moves);
00058
00059 static void attackMajorPiece(const NumEffectState& state, PieceMask pins,
00060 MoveVector& moves);
00061 static void escapeAll(const NumEffectState& state, MoveVector& moves);
00065 static void escapeNormalPiece(const NumEffectState& state,
00066 Piece escape, MoveVector& moves,
00067 bool add_support_only=false);
00071 static void escapeFromLastMove(const NumEffectState& state,
00072 Move last_move, MoveVector& moves);
00073 static void escapeFromLastMoveOtherThanPawn(const NumEffectState& state,
00074 Move last_move, MoveVector& moves);
00078 static bool escapeByMoveOnly(const NumEffectState& state,
00079 Piece piece, MoveVector& moves);
00080 static void attackGoldWithPawn(const NumEffectState& state,
00081 PieceMask pins, MoveVector& moves);
00082 static void attackWithKnight(const NumEffectState& state,
00083 PieceMask pins, Position attack_from,
00084 bool has_knight, MoveVector& moves);
00085 static void attackSilverWithPawn(const NumEffectState& state,
00086 PieceMask pins, MoveVector& moves);
00087 static void attackKnightWithPawn(const NumEffectState& state,
00088 PieceMask pins, MoveVector& moves);
00092 static void advanceBishop(const NumEffectState& state,
00093 MoveVector& moves);
00094 template <Direction DIR>
00095 static void advanceBishop(const NumEffectState& state,
00096 const Position from, MoveVector& moves);
00097 static void attackKing8(const NumEffectState& state, PieceMask pins,
00098 MoveVector& moves);
00099 static void attackToPinned(const NumEffectState& state, PieceMask pins,
00100 MoveVector& moves);
00101
00102 static void utilizePromoted(const NumEffectState& state,
00103 Piece target,
00104 MoveVector& moves);
00105
00106 static void breakThreatmate(const NumEffectState& state,
00107 Move threatmate, PieceMask pins,
00108 MoveVector& moves);
00109 static void kingWalk(const NumEffectState& state,
00110 MoveVector& moves);
00111
00112 struct CaptureGenerator
00113 {
00114 const NumEffectState *state;
00115 MoveVector& out;
00116 void operator()(Piece target_piece)
00117 {
00118 QuiescenceGenerator<P>::capture(*state, target_piece.position(), out);
00119 }
00120 };
00121 struct CaptureGeneratorWithCheck
00122 {
00123 const NumEffectState *state;
00124 MoveVector& out;
00125 Piece dont_capture;
00126 void operator()(Piece target_piece)
00127 {
00128 if (target_piece != dont_capture)
00129 QuiescenceGenerator<P>::capture(*state, target_piece.position(), out);
00130 }
00131 };
00132
00133 private:
00134 static void attackMajorPieceSecondSelection(bool target_has_support,
00135 const MoveVector& src,
00136 MoveVector& out);
00137 static void attackMajorPieceFirstSelection(const NumEffectState& state,
00138 PieceMask pins,
00139 const MoveVector& all_moves,
00140 MoveVector& moves,
00141 MoveVector& expensive_drops);
00142 static void attackMajorPieceZerothSelection(const NumEffectState& state,
00143 const MoveVector& src,
00144 Position target,
00145 MoveVector& open_out,
00146 MoveVector& out);
00147 };
00148 }
00149 }
00150
00151
00152
00153
00154 template <osl::Player P>
00155 inline
00156 void osl::search::QuiescenceGenerator<P>::
00157 capture(const NumEffectState& state, Position target, MoveVector& moves)
00158 {
00159 using namespace move_action;
00160 MoveVector all_moves;
00161 Store store(all_moves);
00162 move_generator::Capture<P>::generate(state, target, store);
00163 for (MoveVector::const_iterator p=all_moves.begin(); p!=all_moves.end(); ++p)
00164 {
00165 if (ShouldPromoteCut::canIgnoreMove<P>(*p))
00166 continue;
00167 moves.push_back(*p);
00168 }
00169 }
00170
00171 template <osl::Player P>
00172 template <osl::Ptype PTYPE>
00173 inline
00174 void osl::search::QuiescenceGenerator<P>::
00175 promote(const NumEffectState& state, MoveVector& moves)
00176 {
00177 assert(moves.empty());
00178 using namespace move_action;
00179 Store store(moves);
00180 move_generator::Promote<P,NumEffectState,Store>
00181 ::template generateMovesPtype<PTYPE>(state, store);
00182 return;
00183 }
00184
00185 #endif
00186
00187
00188
00189