示例#1
0
文件: movement.cpp 项目: Oxyd/APNS
int check_captures(position src, position dst, board const& board,
                   piece what, OutIter out) {
  piece::color_t const player = what.color();
  board::mask supporters;

  int score = 0;

  if (trap(dst)) {
    supporters = neighbourhood(dst) & board.player(player);
    supporters[src] = false;

    // Check for piece stepping into a trap.
    if (supporters.empty()) {
      *out++ = elementary_step::make_capture(dst, what);
      score -= CAPTURE_COEF * cost(what, src);
    }
  }

  // Check for piece abandoning another one standing on a trap.
  if (neighbourhood(src) & board::mask::TRAPS && !trap(dst)) {
    position const trap =
      (neighbourhood(src) & board::mask::TRAPS).first_set();
    boost::optional<piece> const trapped = board.get(trap);
    if (trapped) {
      piece::color_t const trapped_player = trapped->color();
      supporters = neighbourhood(trap) & board.player(trapped_player);
      supporters[src] = false;

      if (supporters.empty()) {
        *out++ = elementary_step::make_capture(trap, *trapped);
        score +=
          (trapped->color() == what.color() ? -1 : +1) *
          CAPTURE_COEF * cost(*trapped, trap);
      }
    }
  }

  return score;
}