All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
quiescenceGenerator.h
Go to the documentation of this file.
1 /* quiescenceGenerator.h
2  */
3 #ifndef OSL_QUIESCENCEGENERATOR_H
4 #define OSL_QUIESCENCEGENERATOR_H
5 
14 #include "osl/move_action/store.h"
15 #include "osl/eval/pieceEval.h"
17 #include "osl/container/square8.h"
18 #include <boost/foreach.hpp>
19 
20 namespace osl
21 {
22  namespace search
23  {
27  template <Player P>
29  {
34  template <Ptype PTYPE, bool has_dont_capture>
35  static void capture(const NumEffectState&,
36  MoveVector& moves, Piece dont_capture);
40  static void capture(const NumEffectState&,
41  Square target, MoveVector& moves);
45  static void capture1(const NumEffectState& state,
46  Square target, MoveVector& moves)
47  {
48  move_generator::GenerateCapture::generate1(P, state, target, moves);
49  }
50  static void promote(const NumEffectState&, PieceMask pins,
51  MoveVector& moves);
52  template <Ptype PTYPE>
53  static void promote(const NumEffectState&, MoveVector& moves);
54  template <Ptype PTYPE, size_t N>
55  static void promoteN(const NumEffectState&, MoveVector& moves,
56  const HistoryTable& table);
57  static void check(const NumEffectState&, PieceMask pins,
58  MoveVector& moves, bool no_liberty=false);
59  static void check(const NumEffectState&, PieceMask pins, bool no_liberty,
60  const Square8& sendoffs, MoveVector& moves);
61  static void escapeKing(const NumEffectState& state, MoveVector& moves);
65  static bool escapeKingInTakeBack(const NumEffectState& state, MoveVector& moves, bool check_by_lance);
66  static void dropMajorPiece(const NumEffectState& state, MoveVector& moves);
67  static void dropMajorPiece3(const NumEffectState& state, MoveVector& moves,
68  const HistoryTable& table);
69 
70  static void attackMajorPiece(const NumEffectState& state, PieceMask pins,
71  MoveVector& moves);
72  static void escapeAll(const NumEffectState& state, MoveVector& moves);
76  static void escapeNormalPiece(const NumEffectState& state,
77  Piece escape, MoveVector& moves,
78  bool add_support_only=false);
82  template <class EvalT>
83  static void escapeFromLastMove(const NumEffectState& state,
84  Move last_move, MoveVector& moves);
85  template <class EvalT>
86  static void escapeFromLastMoveOtherThanPawn(const NumEffectState& state,
87  Move last_move, MoveVector& moves);
91  static bool escapeByMoveOnly(const NumEffectState& state,
92  Piece piece, MoveVector& moves);
93  static void attackGoldWithPawn(const NumEffectState& state,
94  PieceMask pins, MoveVector& moves);
95  static void attackWithKnight(const NumEffectState& state,
96  PieceMask pins, Square attack_from,
97  bool has_knight, MoveVector& moves);
98  static void attackSilverWithPawn(const NumEffectState& state,
99  PieceMask pins, MoveVector& moves);
100  static void attackKnightWithPawn(const NumEffectState& state,
101  PieceMask pins, MoveVector& moves);
105  static void advanceBishop(const NumEffectState& state,
106  MoveVector& moves);
107  template <Direction DIR>
108  static void advanceBishop(const NumEffectState& state,
109  const Square from, MoveVector& moves);
110  static void attackKing8(const NumEffectState& state, PieceMask pins,
111  MoveVector& moves);
112  static void attackToPinned(const NumEffectState& state, PieceMask pins,
113  MoveVector& moves);
114 
115  static void utilizePromoted(const NumEffectState& state,
116  Piece target,
117  MoveVector& moves);
118 
119  static void breakThreatmate(const NumEffectState& state,
120  Move threatmate, PieceMask pins,
121  MoveVector& moves);
122  static void kingWalk(const NumEffectState& state,
123  MoveVector& moves);
124  private:
125  static void attackMajorPieceSecondSelection(bool target_has_support,
126  const MoveVector& src,
127  MoveVector& out);
128  static void attackMajorPieceFirstSelection(const NumEffectState& state,
129  PieceMask pins,
130  const MoveVector& all_moves,
131  MoveVector& moves,
132  MoveVector& expensive_drops);
133  static void attackMajorPieceZerothSelection(const NumEffectState& state,
134  const MoveVector& src,
135  Square target,
136  MoveVector& open_out,
137  MoveVector& out);
138  };
139  } // namespace search
140 } // namespace osl
141 
142 
143 
144 
145 template <osl::Player P>
146 inline
148 capture(const NumEffectState& state, Square target, MoveVector& moves)
149 {
150  move_generator::GenerateCapture::generate(P,state, target, moves);
151 #ifndef NDEBUG
152  BOOST_FOREACH(Move m, moves)
153  assert(! ShouldPromoteCut::canIgnoreMove<P>(m));
154 #endif
155 }
156 
157 template <osl::Player P>
158 template <osl::Ptype PTYPE>
159 inline
161 promote(const NumEffectState& state, MoveVector& moves)
162 {
163  move_generator::Promote<P>::template generatePtype<PTYPE>(state, moves);
164 }
165 
166 template <osl::Player P>
167 template <osl::Ptype PTYPE, size_t N>
168 inline
170 promoteN(const NumEffectState& state, MoveVector& moves, const HistoryTable& table)
171 {
172  MoveVector all;
173  move_generator::Promote<P>::template generatePtype<PTYPE>(state, all);
174  FixedCapacityVector<std::pair<int,Move>, 16*2> selected;
175  BOOST_FOREACH(Move m, all) {
176  if (state.hasEffectAt(alt(P), m.to()))
177  continue;
178  selected.push_back(std::make_pair(table.value(m), m));
179  }
180  std::sort(selected.begin(), selected.end());
181  for (size_t i=0; i<std::min(N, selected.size()); ++i)
182  moves.push_back(selected[selected.size()-1-i].second);
183 }
184 
185 #endif /* OSL_QUIESCENCEGENERATOR_H */
186 // ;;; Local Variables:
187 // ;;; mode:c++
188 // ;;; c-basic-offset:2
189 // ;;; End: