3 #ifndef QUIESCENCEGENERATOR_TCC 
    4 #define QUIESCENCEGENERATOR_TCC 
   19 template <osl::Player P> 
 
   20 template <osl::Ptype PTYPE, 
bool has_dont_capture> 
 
   24   mask_t pieces = state.effectedMask(P).template selectBit<PTYPE>()
 
   27   if (has_dont_capture && dont_capture.
isPiece() && (dont_capture.
ptype() == PTYPE))
 
   29     while (pieces.any()) {
 
   31       if (target != dont_capture)
 
   37     while (pieces.any()) {
 
   43       && state.hasPieceOnStand<
LANCE>(P))
 
   49     MoveVector::const_iterator original_end = moves.end();
 
   50     for (MoveVector::const_iterator p=moves.begin(); p!=original_end; ++p)
 
   52       const Square from = p->from();
 
   53       if ((p->oldPtype() == 
PAWN)
 
   62 template <osl::Player P> 
inline 
   65                                PieceMask pins, 
const MoveVector& all_moves,
 
   67                                MoveVector& expensive_drops)
 
   69   BOOST_FOREACH(
Move m, all_moves)
 
   73       const int defense = state.countEffect(
alt(P),to, pins);
 
   74       int offense = state.countEffect(P,to) + (m.
isDrop() ? 1 : 0);
 
   75       if (defense >= offense)
 
   76         offense += AdditionalEffect::count2(state, to, P);
 
   79         if (defense > offense)
 
   84         if (defense && (offense==1))
 
   86           if (! (state.hasEffectByPtype<
ROOK>(
alt(P),to)
 
   87                  && state.hasEffectByPtype<
BISHOP>(
alt(P),to)))
 
   92       if ((defense >= offense)
 
   97         const Square front_position
 
   99         const Piece front_piece = state.pieceAt(front_position);
 
  107         const Square back_position
 
  109         if (state.pieceOnBoard(back_position).isEmpty())
 
  110           moves.push_back(
Move(back_position, 
PAWN, P));
 
  113       const bool is_large_piece
 
  117           || (is_large_piece && defense))
 
  118         expensive_drops.push_back(m);
 
  125 template <osl::Player P> 
inline 
  128                                 const MoveVector& src,
 
  131   BOOST_FOREACH(
Move m, src)
 
  134     if (target_has_support
 
  143 template <osl::Player P>
 
  146                                 const MoveVector& src,
 
  148                                 MoveVector& open_out,
 
  151   BOOST_FOREACH(
Move m, src)
 
  153     assert(!ShouldPromoteCut::canIgnoreAndNotDrop<P>(m));
 
  156       && state.hasEffectAt<P>(m.
from())
 
  157       && (state.hasEffectByPtype<
LANCE>(P, m.
from())
 
  158           || state.hasEffectByPtype<
BISHOP>(P, m.
from())
 
  159           || state.hasEffectByPtype<
ROOK>(P, m.
from()))
 
  167         open_out.push_back(m);
 
  177 template <osl::Player P>
 
  182   using namespace move_action;
 
  184   MoveVector unsupported, supported;
 
  187        i < PtypeTraits<ROOK>::indexLimit; i++)
 
  189     const Piece p = state.pieceOf(i);
 
  194       const bool unstable_rook = (p.
ptype() == 
ROOK)
 
  198       if (state.hasEffectAt(
alt(P), target) && (! unstable_rook))
 
  200         move_generator::GenerateAddEffectWithEffect::generate<false>
 
  202         attackMajorPieceZerothSelection(state, work, target, moves, supported); 
 
  204       else if (unstable_rook || (! state.hasEffectAt(P, target)))
 
  207         move_generator::GenerateAddEffectWithEffect::generate<false>
 
  209         attackMajorPieceZerothSelection(state, work, target, moves, unsupported);
 
  215   MoveVector drops_supported, drops_unsupported;
 
  216   attackMajorPieceFirstSelection(state, pins, unsupported, moves, 
 
  218   attackMajorPieceFirstSelection(state, pins, supported, moves, 
 
  221   if (moves.size() > 5)
 
  223   attackMajorPieceSecondSelection(
false, drops_unsupported, moves);
 
  224   if (moves.size() > 5)
 
  226   attackMajorPieceSecondSelection(
true, drops_supported, moves);
 
  229 template <osl::Player P>
 
  235   using namespace move_action;
 
  236   MoveVector all_moves;
 
  237   const Piece attack_piece
 
  238     = state.findCheapAttack(
alt(P), escape.
square());
 
  239   const int attack_ptype_value 
 
  242   if (! add_support_only)
 
  244     GenerateEscape<P>::generateCheap(state, escape, all_moves);
 
  245     BOOST_FOREACH(
Move m, all_moves)
 
  250         if (! state.hasEffectAt<P>(to))
 
  252 #ifdef QSEARCH_EXPENSIVE_BLOCK 
  263         if (m.
from() != escape_from)
 
  266           if (! state.hasMultipleEffectAt(P, to))
 
  273         assert(! ShouldPromoteCut::canIgnoreMove<P>(m));
 
  287   if (state.hasEffectAt<P>(escape_from)
 
  288       || (state.countEffect(
alt(P), escape_from) != 1))
 
  291   move_generator::GenerateAddEffectWithEffect::generate<false>
 
  292     (P, state, escape_from, all_moves);
 
  293   const size_t escape_moves = moves.size();
 
  295   BOOST_FOREACH(
Move m, all_moves)
 
  301           && (! state.hasEffectAt<P>(to)))
 
  311       const int defense = state.countEffect(P,to);
 
  312       const int offense = state.countEffect(
alt(P),to);
 
  313       if (offense >= defense)
 
  317       assert(! ShouldPromoteCut::canIgnoreMove<P>(m));
 
  325   if (state.hasEffectByPtype<
BISHOP>(
alt(P), escape_from)
 
  326       && state.hasPieceOnStand<
BISHOP>(P))
 
  328     const Piece bishop = state.findAttackAt<
BISHOP>(
alt(P), escape_from);
 
  334       while (state.pieceAt(p).isEmpty())
 
  336         if (state.hasEffectAt<P>(p))
 
  346   if (escape_moves == moves.size()) 
 
  347     moves.push_back(not_drop.begin(), not_drop.end());
 
  350 template <osl::Player P>
 
  355   const PieceMask pieces = state.effectedMask(
alt(P)) & state.piecesOnBoard(P);
 
  356   bool found_attacked_piece = 
false;
 
  363     found_attacked_piece = 
true;
 
  364     escapeNormalPiece(state, p, moves);
 
  366   m = pieces.selectBit<
BISHOP>();
 
  372     found_attacked_piece = 
true;
 
  373     escapeNormalPiece(state, p, moves);
 
  376   if (found_attacked_piece)
 
  378   m = pieces.selectBit<
GOLD>();
 
  384     escapeNormalPiece(state, p, moves);
 
  387   m = pieces.selectBit<
SILVER>();
 
  393     escapeNormalPiece(state, p, moves);
 
  396   m = pieces.selectBit<
KNIGHT>();
 
  406   m = pieces.selectBit<
LANCE>();
 
  413     escapeNormalPiece(state, p, moves, 
true);
 
  416   m = pieces.selectBit<
PAWN>();
 
  423     escapeNormalPiece(state, p, moves, 
true);
 
  430 template <osl::Player P>
 
  431 template <
class EvalT>
 
  442   EffectUtil::findThreat<EvalT>(state, from, last_move.
ptypeO(), targets);
 
  445   assert(targets[0].ptype() != 
KING);
 
  447   escapeNormalPiece(state, targets[0], moves, 
 
  451   if (targets.size() > 1)
 
  452     escapeNormalPiece(state, targets[1], moves, 
 
  458 template <osl::Player P>
 
  464   MoveVector all_moves;
 
  470   const bool consider_shadowing
 
  471     = state.hasEffectByPtype<
LANCE>(Opponent, from)
 
  472     || state.hasEffectByPtype<
ROOK>(Opponent, from)
 
  473     || state.hasEffectByPtype<
BISHOP>(Opponent, from);
 
  474   const bool is_major = 
isMajor(piece.ptype());
 
  475   const bool chase_danger
 
  476     = (! state.hasEffectAt(P, from)
 
  477        && (state.hasMultipleEffectAt(
alt(P), from)
 
  479   BOOST_FOREACH(
Move m, all_moves)
 
  485     const bool safe_position
 
  486       = (consider_shadowing
 
  487          ? (! state.hasEffectByWithRemove<Opponent>(to, from))
 
  488          : (! state.hasEffectAt<Opponent>(to)));
 
  491       if (! is_major || ! chase_danger)
 
  493       if (! to.canPromote<Opponent>())
 
  503 template <osl::Player P>
 
  505 check(
const NumEffectState& state, PieceMask pins, MoveVector& 
moves,
 
  509   const Square king_position = state.kingSquare(
alt(P));
 
  510   effect_util::SendOffSquare::find<P>(state, king_position, sendoffs);
 
  511   check(state, pins, no_liberty, sendoffs, moves);
 
  515 template <osl::Player P>
 
  517 check(
const NumEffectState& state, PieceMask pins, 
bool no_liberty, 
 
  518       const Square8& sendoffs, MoveVector& 
moves)
 
  520   using namespace move_action;
 
  521   MoveVector all_moves;
 
  522   const Square king_position = state.kingSquare(
alt(P));
 
  523   move_generator::GenerateAddEffectWithEffect::generate<true>
 
  524     (P, state, king_position, all_moves);
 
  526   MoveVector merginal_moves;
 
  527   BOOST_FOREACH(
Move m, all_moves)
 
  530     assert(! ShouldPromoteCut::canIgnoreAndNotDrop<P>(m));
 
  542       && state.hasEffectAt<P>(m.
from())
 
  543       && (state.hasEffectByPtype<
LANCE>(P, m.
from())
 
  544           || state.hasEffectByPtype<
BISHOP>(P, m.
from())
 
  545           || state.hasEffectByPtype<
ROOK>(P, m.
from()))
 
  546       && ! state.hasEffectIf(m.
ptypeO(), m.
to(), king_position);
 
  552         const Square front_position
 
  554         const Piece front_piece = state.pieceAt(front_position);
 
  558       if (! sendoffs.isMember(to))
 
  560         const int defense = state.countEffect(
alt(P),to, pins);
 
  561         int offense = state.countEffect(P,to) + no_liberty;
 
  562         const bool may_effective = offense && (! sendoffs.empty());
 
  565         if (defense >= offense)
 
  566           offense += AdditionalEffect::count2(state, to, P);
 
  567         if (defense >= offense)
 
  568           offense += ShadowEffect::count2(state, to, P);
 
  571           const Square front_position
 
  573           if (state.hasEffectAt<P>(front_position))
 
  576         if (defense > offense)
 
  578           const bool side_attack
 
  579             = (king_position.x() == 1 || king_position.x() == 9)
 
  584         else if (defense == offense)
 
  587               || state.hasEffectByPtype<
PAWN>(P, to)
 
  588               || state.hasEffectByPtype<
LANCE>(P, to))
 
  590           else if (may_effective)
 
  591             merginal_moves.push_back(m);
 
  600       const Square back_position
 
  602       if (state.pieceOnBoard(back_position).isEmpty())
 
  603         moves.push_back(
Move(back_position, 
PAWN, P));
 
  607   if (moves.size() < 3)
 
  608     moves.push_back(merginal_moves.begin(), merginal_moves.end());
 
  611 template <osl::Player P>
 
  613 promote(
const NumEffectState& state, PieceMask pins, MoveVector& 
moves)
 
  615   using namespace move_action;
 
  616   MoveVector all_moves;
 
  619   BOOST_FOREACH(
Move m, all_moves)
 
  622     const int defense = state.countEffect(
alt(P),to, pins);
 
  623     int offense = state.countEffect(P,to);
 
  624     if (defense >= offense)
 
  625       offense += AdditionalEffect::count2(state, to, P);
 
  627         && defense && offense + 1 >= defense)
 
  634              i < PtypeTraits<ROOK>::indexLimit; ++i)
 
  636           const Piece rook = state.pieceOf(i);
 
  638               || rook.
square().template canPromote<P>())
 
  641           if (state.pieceOnBoard(mid).isEmpty()
 
  642               && state.isEmptyBetween(m.
from(), mid)
 
  643               && state.isEmptyBetween(rook.
square(), mid))
 
  649         if (state.hasPieceOnStand<
LANCE>(P))
 
  654     if (defense > offense)
 
  658     if ((defense == offense)
 
  666 template <osl::Player P>
 
  670   using namespace move_action;
 
  671   MoveVector all_moves;
 
  675   MoveVector major_drop;
 
  678   const Square king_position = state.kingSquare(
alt(P));
 
  679   const int king_x = king_position.
x();
 
  680   BOOST_FOREACH(
Move m, all_moves)
 
  683     assert(! ShouldPromoteCut::canIgnoreAndNotDrop<P>(m));
 
  693     const int defense = state.countEffect(
alt(P),to,pins);
 
  694     int offense = state.countEffect(P,to) + (m.
isDrop() ? 1 : 0);
 
  695     if (defense >= offense)
 
  696       offense += AdditionalEffect::count2(state, to, P);
 
  700       if (state.hasEffectAt<P>(head))
 
  703     if (defense > offense)
 
  705     if (defense == offense)
 
  716             && abs(to.y() - king_position.y()) <= 2)
 
  719           major_drop.push_back(m);
 
  721           not_drop.push_back(m);
 
  727       const int y = to.y();
 
  728       if (((P == 
BLACK) && (y == 1))
 
  729           || ((P == 
WHITE) && (y == 9)))
 
  735       if (state.hasEffectByPtype<
PAWN>(
alt(P), to))
 
  737       if (state.hasEffectByPtype<
LANCE>(
alt(P), to))
 
  739         not_drop.push_back(m);
 
  743     if (! Neighboring8::isNeighboring8(king_position, to))
 
  746       not_drop.push_back(m);
 
  750   const size_t minimum_moves
 
  751     = (king_position.squareForBlack<P>().y() == 1) ? 3 : 2;
 
  752   for (MoveVector::const_iterator p=not8.begin();
 
  753        (p!=not8.end()) && (moves.size() <= minimum_moves); ++p)
 
  757   for (MoveVector::const_iterator p=not_drop.begin();
 
  758        (p!=not_drop.end()) && (moves.size() <= minimum_moves); ++p)
 
  762   for (MoveVector::const_iterator p=major_drop.begin();
 
  763        (p!=major_drop.end()) && (moves.size() <= minimum_moves); ++p)
 
  769 template <osl::Player P>
 
  773   using namespace move_action;
 
  774   MoveVector all_moves;
 
  777   BOOST_FOREACH(
Move m, all_moves)
 
  780     assert(!ShouldPromoteCut::canIgnoreAndNotDrop<P>(m));
 
  791     const int defense = state.countEffect(
alt(P),to,pins);
 
  792     int offense = state.countEffect(P,to) + (m.
isDrop() ? 1 : 0);
 
  793     if (defense >= offense)
 
  794       offense += AdditionalEffect::count2(state, to, P);
 
  798       if (state.hasEffectAt<P>(head))
 
  801     if (defense > offense)
 
  803     if (defense == offense)
 
  811       const Square front_position
 
  813       const Piece front_piece = state.pieceAt(front_position);
 
  821 template <osl::Player P>
 
  833   MoveVector all_moves;
 
  838   bool has_good_capture = 
false;
 
  839   bool may_have_additional = 
false; 
 
  840   BOOST_FOREACH(
Move m, all_moves)
 
  846         has_good_capture =
true;
 
  851     int offense = state.countEffect(P, to);
 
  852     const int defense = state.countEffect(Opponent, to);
 
  853     const int additional = AdditionalEffect::count2(state, to, P);
 
  854     if (defense >= offense)
 
  856       offense += additional;
 
  857       may_have_additional |= (additional > 0);
 
  859     if (defense >= offense)
 
  866   if ((! has_good_capture) && may_have_additional)
 
  867     moves.push_back(others.begin(), others.end());
 
  870 template <osl::Player P>
 
  873                 Move threatmate, PieceMask pins, MoveVector& 
moves)
 
  875   MoveVector all_moves, major_piece, major_sacrifice;
 
  880   move_generator::GenerateAddEffectWithEffect::generate<false>
 
  881     (P, state, 
target, all_moves);
 
  883   BOOST_FOREACH(
Move m, all_moves)
 
  890       assert(!ShouldPromoteCut::canIgnoreAndNotDrop<P>(m));
 
  894           && state.hasEffectByPiece(state.pieceOnBoard(m.
from()), target))
 
  898     const int me = state.countEffect(P, to) + (m.
isDrop() ? 1 : 0);
 
  899     const int op = state.countEffect(
alt(P), to, pins);
 
  900     if ((me >= 2) || (op == 0))
 
  905           major_sacrifice.push_back(m);
 
  907           major_piece.push_back(m);
 
  912             && (to.
x() == 1 || to.
x() == 9))
 
  913           major_piece.push_back(m);
 
  924     if (state.hasPieceOnStand<
PAWN>(P)
 
  925         && ! state.isPawnMaskSet(P, target.x())
 
  927       moves.push_back(
Move(target, 
PAWN, P));
 
  928     else if (state.hasPieceOnStand<
LANCE>(P)
 
  931     else if (state.hasPieceOnStand<
KNIGHT>(P)
 
  934     else if (state.hasPieceOnStand<
SILVER>(P))
 
  936     else if (state.hasPieceOnStand<
GOLD>(P))
 
  937       moves.push_back(
Move(target, 
GOLD, P));
 
  940   BreakThreatmate::findBlockLong(state, threatmate, all_moves);
 
  941   if (! all_moves.empty()) 
 
  944     if (state.hasPieceOnStand<
PAWN>(P)) cheapest = 
PAWN;
 
  945     else if (state.hasPieceOnStand<
LANCE>(P)) cheapest = 
LANCE;
 
  946     else if (state.hasPieceOnStand<
KNIGHT>(P)) cheapest = 
KNIGHT;
 
  947     BOOST_FOREACH(
Move m, all_moves) {
 
  948       const int d = state.countEffect(P, m.
to()) + m.
isDrop();
 
  949       const int a = state.countEffect(
alt(P), m.
to());
 
  950       if (a >= d && ! (d >= 2 && m.
ptype() == 
PAWN))
 
  961   const Square king_position = state.kingSquare(P);
 
  970       if (state.hasEffectAt(
alt(P), p.
square()))
 
  974     BOOST_FOREACH(
Move m, all_moves)
 
  977       assert(!ShouldPromoteCut::canIgnoreAndNotDrop<P>(m));
 
  989   const size_t minimum_moves = 8;
 
  990   for (MoveVector::const_iterator p=major_piece.begin(); 
 
  991        p!=major_piece.end() && moves.size() < minimum_moves; ++p)
 
  995   for (MoveVector::const_iterator p=major_sacrifice.begin(); 
 
  996        p!=major_sacrifice.end() && moves.size() < minimum_moves; ++p)
 
 1002 template <osl::Player P>
 
 1007   using namespace move_action;
 
 1009   const bool has_pawn   = state.hasPieceOnStand<
PAWN>(P);
 
 1010   const bool has_lance  = state.hasPieceOnStand<
LANCE>(P);
 
 1011   const bool has_knight = state.hasPieceOnStand<
KNIGHT>(P);
 
 1012   const bool has_silver = state.hasPieceOnStand<
SILVER>(P);
 
 1014        i < PtypeTraits<GOLD>::indexLimit; ++i)
 
 1016     const Piece p = state.pieceOf(i);
 
 1020     if (state.pieceAt(head).isEmpty())
 
 1023       const int defense = state.countEffect(
alt(P), head, pins);
 
 1024       int attack = state.countEffect(P, head)
 
 1026       if (defense >= attack)
 
 1027         attack += AdditionalEffect::count2(state, head, P);
 
 1033         if (defense <= attack
 
 1034             || state.hasEffectByPtype<
BISHOP>(P, origin)) 
 
 1036           const Piece candidate = state.pieceAt(origin);
 
 1040             moves.push_back(move);
 
 1046       if (defense <= attack)
 
 1048         if (has_pawn && !state.template isPawnMaskSet<P>(head.
x()))
 
 1051           moves.push_back(move);
 
 1056           moves.push_back(move);
 
 1061           moves.push_back(move);
 
 1064       const bool generate_long_lance = has_lance 
 
 1065         && (! state.hasPieceOnStand<
PAWN>(
alt(P))
 
 1067       if (generate_long_lance) 
 
 1070              state.pieceAt(to).isEmpty(); 
 
 1073           const int defense = state.countEffect(
alt(P), to, pins);
 
 1074           const int attack = state.countEffect(P, to);
 
 1075           if (defense > attack)
 
 1078           moves.push_back(move);
 
 1083     if (! state.pieceAt(head).isEdge())
 
 1086       attackWithKnight(state, pins, knight_l, has_knight, moves);
 
 1088       attackWithKnight(state, pins, knight_r, has_knight, moves);
 
 1093 template <osl::Player P>
 
 1097                      bool has_knight, MoveVector& 
moves) 
 
 1099   if (state.pieceAt(attack_from) != Piece::EMPTY())
 
 1102   const int defense = state.countEffect(
alt(P), attack_from, pins);
 
 1103   int attack = state.countEffect(P, attack_from);
 
 1106       && (attack == 1 || (has_knight && attack == 0)))
 
 1108     const Piece gold = state.findAttackAt<
GOLD>(
alt(P), attack_from);
 
 1114       if (state.pieceAt(guarded).isOnBoardByOwner(
alt(P))
 
 1115           && (state.countEffect(
alt(P), guarded) 
 
 1116               <= state.countEffect(P, guarded)))
 
 1121     const Piece head_piece = state.pieceOnBoard(head);
 
 1123       if (state.hasEffectByPiece(head_piece, attack_from)
 
 1124           && state.hasEffectByPtype<
BISHOP>(P, head))
 
 1129   if (defense > attack)
 
 1135     moves.push_back(drop);
 
 1138   if (defense < attack)
 
 1146       const int n = mask.takeOneBit();
 
 1147       const Piece knight = state.pieceOf(n);
 
 1152       assert(state.isAlmostValidMove<
false>(move));
 
 1153       moves.push_back(move);
 
 1158 template <osl::Player P>
 
 1163   using namespace move_action;
 
 1165   const bool has_pawn = state.hasPieceOnStand<
PAWN>(P);
 
 1167        i < PtypeTraits<KNIGHT>::indexLimit; ++i)
 
 1169     const Piece p = state.pieceOf(i);
 
 1174       if (state.pieceAt(head).isEmpty())
 
 1176         const int defense = state.countEffect(
alt(P), head, pins);
 
 1177         const int offense = state.countEffect(P, head);
 
 1178         if ((defense <= offense)
 
 1182           const Piece candidate = state.pieceAt(origin);
 
 1186             moves.push_back(move);
 
 1189         if (has_pawn && !state.template isPawnMaskSet<P>(head.
x())
 
 1190             && (defense <= offense+1))
 
 1193           moves.push_back(move);
 
 1200 template <osl::Player P>
 
 1205   using namespace move_action;
 
 1207   const bool has_pawn   = state.hasPieceOnStand<
PAWN>(P);
 
 1208   const bool has_lance  = state.hasPieceOnStand<
LANCE>(P);
 
 1209   const bool has_knight = state.hasPieceOnStand<
KNIGHT>(P);
 
 1210   const bool has_silver = state.hasPieceOnStand<
SILVER>(P);
 
 1211   const Square opponent_king = state.kingSquare(
alt(P));
 
 1213        i < PtypeTraits<SILVER>::indexLimit; ++i)
 
 1215     const Piece p = state.pieceOf(i);
 
 1220     if (state.pieceAt(head).isEmpty())
 
 1222       const int defense = state.countEffect(
alt(P), head, pins);
 
 1223       int attack = state.countEffect(P, head) 
 
 1225       if (defense >= attack)
 
 1226         attack += AdditionalEffect::count2(state, head, P);
 
 1227       const bool near_king 
 
 1230       if (defense > attack)
 
 1239         const Piece candidate = state.pieceAt(origin);
 
 1243           moves.push_back(move);
 
 1246       if (has_pawn && !state.template isPawnMaskSet<P>(head.
x()))
 
 1249         moves.push_back(move);
 
 1253       if (defense <= attack)
 
 1258           moves.push_back(move);
 
 1263           moves.push_back(move);
 
 1268     if (! state.pieceAt(head).isEdge())
 
 1271       attackWithKnight(state, pins, knight_l, has_knight, moves);
 
 1273       attackWithKnight(state, pins, knight_r, has_knight, moves);
 
 1276     const CArray<Square,2> side = {{
 
 1280     BOOST_FOREACH(
Square s, side) {
 
 1281       if (! state.pieceAt(s).isEmpty())
 
 1283       if (state.countEffect(P, s) 
 
 1284           < state.countEffect(
alt(P), s))
 
 1286       MoveVector candidate;
 
 1289       BOOST_FOREACH(
Move m, candidate) {
 
 1291             || state.hasEffectByPiece(state.pieceOnBoard(m.
from()),
 
 1294         assert(! ShouldPromoteCut::canIgnoreMove<P>(m));
 
 1301 template <osl::Player P>
 
 1305   const Piece my_king = state.kingPiece<P>();
 
 1306   MoveVector all_moves;
 
 1309   BOOST_FOREACH(
Move m, all_moves)
 
 1311     if (state.hasEffectAt(
alt(P), m.
to()))
 
 1317 template <osl::Player P>
 
 1321   MoveVector all_moves;
 
 1322   GenerateEscape<P>::generateCheap(state, state.template kingPiece<P>(), all_moves);
 
 1324   BOOST_FOREACH(
Move m, all_moves)
 
 1330       if (! state.hasEffectAt<P>(to))
 
 1333                && state.hasMultipleEffectAt(
alt(P), to)))
 
 1342         if (! state.hasMultipleEffectAt(P, to))
 
 1345                  && state.hasMultipleEffectAt(
alt(P), to)))
 
 1354 template <osl::Player P>
 
 1357                      bool check_by_lance) 
 
 1359   bool has_safe_move = 
false;
 
 1360   assert(moves.empty());
 
 1361   MoveVector all_moves;
 
 1364   Square last_drop_to = Square::STAND();
 
 1366   BOOST_FOREACH(
Move m, all_moves)
 
 1372       has_safe_move = 
true; 
 
 1381     const int attack_count = state.countEffect(
alt(P),to);
 
 1382     const int defense_count 
 
 1383       = state.countEffect(P,to) + (m.
isDrop() ? 1 : 0);
 
 1384     if (defense_count <= attack_count)
 
 1386     if ((attack_count == 1) && (! check_by_lance))
 
 1389       has_safe_move = 
true;
 
 1395     if (to != last_drop_to)
 
 1401   if (! has_safe_move)
 
 1402     moves.push_back(drops.begin(), drops.end());
 
 1403   return has_safe_move;
 
 1406 template <osl::Player P>
 
 1411        i < PtypeTraits<BISHOP>::indexLimit; ++i)
 
 1413     const Piece bishop = state.pieceOf(i);
 
 1421     advanceBishop<UL>(state, from, 
moves);
 
 1422     advanceBishop<UR>(state, from, 
moves);
 
 1426 template <osl::Player P>
 
 1427 template <osl::Direction DIR>
 
 1433   for (
Square to=from+offset;; to+=offset)
 
 1435     if (! state.pieceAt(to).isEmpty())
 
 1437     if (to.canPromote<P>())
 
 1442     assert(state.isAlmostValidMove<
false>(move));
 
 1443     moves.push_back(move);
 
 1447 template <osl::Player P>
 
 1448 template <
class EvalT>
 
 1456     escapeFromLastMoveOtherThanPawn<EvalT>(state, last_move, 
moves);
 
 1459   const Square attack_from = last_move.
to();
 
 1461   const Piece target = state.pieceOnBoard(attack_to);
 
 1465   using namespace move_action;
 
 1466   MoveVector all_moves;
 
 1469   BOOST_FOREACH(
Move m, all_moves)
 
 1474     const int defense = state.countEffect(P, to);
 
 1475     const int offense = state.countEffect(
alt(P), to);
 
 1476     if (offense > defense)
 
 1478     if (to == attack_from)
 
 1481       if (offense == defense)
 
 1484       assert(! ShouldPromoteCut::canIgnoreMove<P>(m));
 
 1488     assert(m.
from() == attack_to);
 
 1489     if ((offense == defense)
 
 1494       assert(! ShouldPromoteCut::canIgnoreMove<P>(m));
 
 1502 template <osl::Player P>
 
 1509 template <osl::Player P>
 
 1513   FixedCapacityVector<Move, 27*2> all;
 
 1515   FixedCapacityVector<std::pair<int,Move>, 27*2> selected;
 
 1516   BOOST_FOREACH(
Move m, all) 
 
 1517     selected.push_back(std::make_pair(table.
value(m), m));
 
 1518   std::sort(selected.begin(), selected.end());
 
 1519   for (
int i=0; i<
std::min(3, (
int)selected.size()); ++i)
 
 1520     moves.push_back(selected[selected.size()-1-i].second);