00001
00002
00003 #ifndef OSL_QUIESCENCEGENERATOR_H
00004 #define OSL_QUIESCENCEGENERATOR_H
00005
00006 #include "osl/search/shouldPromoteCut.h"
00007 #include "osl/search/historyTable.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/square8.h"
00018 #include <boost/foreach.hpp>
00019
00020 namespace osl
00021 {
00022 namespace search
00023 {
00027 template <Player P>
00028 struct QuiescenceGenerator
00029 {
00034 template <Ptype PTYPE, bool has_dont_capture>
00035 static void capture(const NumEffectState&,
00036 MoveVector& moves, Piece dont_capture);
00040 static void capture(const NumEffectState&,
00041 Square target, MoveVector& moves);
00045 static void capture1(const NumEffectState& state,
00046 Square target, MoveVector& moves)
00047 {
00048 move_generator::GenerateCapture::generate1(P, state, target, moves);
00049 }
00050 static void promote(const NumEffectState&, PieceMask pins,
00051 MoveVector& moves);
00052 template <Ptype PTYPE>
00053 static void promote(const NumEffectState&, MoveVector& moves);
00054 template <Ptype PTYPE, size_t N>
00055 static void promoteN(const NumEffectState&, MoveVector& moves,
00056 const HistoryTable& table);
00057 static void check(const NumEffectState&, PieceMask pins,
00058 MoveVector& moves, bool no_liberty=false);
00059 static void check(const NumEffectState&, PieceMask pins, bool no_liberty,
00060 const Square8& sendoffs, MoveVector& moves);
00061 static void escapeKing(const NumEffectState& state, MoveVector& moves);
00065 static bool escapeKingInTakeBack(const NumEffectState& state, MoveVector& moves, bool check_by_lance);
00066 static void dropMajorPiece(const NumEffectState& state, MoveVector& moves);
00067 static void dropMajorPiece3(const NumEffectState& state, MoveVector& moves,
00068 const HistoryTable& table);
00069
00070 static void attackMajorPiece(const NumEffectState& state, PieceMask pins,
00071 MoveVector& moves);
00072 static void escapeAll(const NumEffectState& state, MoveVector& moves);
00076 static void escapeNormalPiece(const NumEffectState& state,
00077 Piece escape, MoveVector& moves,
00078 bool add_support_only=false);
00082 template <class EvalT>
00083 static void escapeFromLastMove(const NumEffectState& state,
00084 Move last_move, MoveVector& moves);
00085 template <class EvalT>
00086 static void escapeFromLastMoveOtherThanPawn(const NumEffectState& state,
00087 Move last_move, MoveVector& moves);
00091 static bool escapeByMoveOnly(const NumEffectState& state,
00092 Piece piece, MoveVector& moves);
00093 static void attackGoldWithPawn(const NumEffectState& state,
00094 PieceMask pins, MoveVector& moves);
00095 static void attackWithKnight(const NumEffectState& state,
00096 PieceMask pins, Square attack_from,
00097 bool has_knight, MoveVector& moves);
00098 static void attackSilverWithPawn(const NumEffectState& state,
00099 PieceMask pins, MoveVector& moves);
00100 static void attackKnightWithPawn(const NumEffectState& state,
00101 PieceMask pins, MoveVector& moves);
00105 static void advanceBishop(const NumEffectState& state,
00106 MoveVector& moves);
00107 template <Direction DIR>
00108 static void advanceBishop(const NumEffectState& state,
00109 const Square from, MoveVector& moves);
00110 static void attackKing8(const NumEffectState& state, PieceMask pins,
00111 MoveVector& moves);
00112 static void attackToPinned(const NumEffectState& state, PieceMask pins,
00113 MoveVector& moves);
00114
00115 static void utilizePromoted(const NumEffectState& state,
00116 Piece target,
00117 MoveVector& moves);
00118
00119 static void breakThreatmate(const NumEffectState& state,
00120 Move threatmate, PieceMask pins,
00121 MoveVector& moves);
00122 static void kingWalk(const NumEffectState& state,
00123 MoveVector& moves);
00124 private:
00125 static void attackMajorPieceSecondSelection(bool target_has_support,
00126 const MoveVector& src,
00127 MoveVector& out);
00128 static void attackMajorPieceFirstSelection(const NumEffectState& state,
00129 PieceMask pins,
00130 const MoveVector& all_moves,
00131 MoveVector& moves,
00132 MoveVector& expensive_drops);
00133 static void attackMajorPieceZerothSelection(const NumEffectState& state,
00134 const MoveVector& src,
00135 Square target,
00136 MoveVector& open_out,
00137 MoveVector& out);
00138 };
00139 }
00140 }
00141
00142
00143
00144
00145 template <osl::Player P>
00146 inline
00147 void osl::search::QuiescenceGenerator<P>::
00148 capture(const NumEffectState& state, Square target, MoveVector& moves)
00149 {
00150 move_generator::GenerateCapture::generate(P,state, target, moves);
00151 #ifndef NDEBUG
00152 BOOST_FOREACH(Move m, moves)
00153 assert(! ShouldPromoteCut::canIgnoreMove<P>(m));
00154 #endif
00155 }
00156
00157 template <osl::Player P>
00158 template <osl::Ptype PTYPE>
00159 inline
00160 void osl::search::QuiescenceGenerator<P>::
00161 promote(const NumEffectState& state, MoveVector& moves)
00162 {
00163 move_generator::Promote<P>::template generatePtype<PTYPE>(state, moves);
00164 }
00165
00166 template <osl::Player P>
00167 template <osl::Ptype PTYPE, size_t N>
00168 inline
00169 void osl::search::QuiescenceGenerator<P>::
00170 promoteN(const NumEffectState& state, MoveVector& moves, const HistoryTable& table)
00171 {
00172 MoveVector all;
00173 move_generator::Promote<P>::template generatePtype<PTYPE>(state, all);
00174 FixedCapacityVector<std::pair<int,Move>, 16*2> selected;
00175 BOOST_FOREACH(Move m, all) {
00176 if (state.hasEffectAt(alt(P), m.to()))
00177 continue;
00178 selected.push_back(std::make_pair(table.value(m), m));
00179 }
00180 std::sort(selected.begin(), selected.end());
00181 for (size_t i=0; i<std::min(N, selected.size()); ++i)
00182 moves.push_back(selected[selected.size()-1-i].second);
00183 }
00184
00185 #endif
00186
00187
00188
00189