00001
00002
00003 #include "osl/checkmate/checkmateIfCapture.h"
00004 #include "osl/checkmate/fixedDepthSearcher.h"
00005 #include "osl/effect_util/effectUtil.h"
00006 #include "osl/move_generator/capture_.h"
00007 #include "osl/move_action/store.h"
00008 #include "osl/apply_move/applyMove.h"
00009
00010 struct osl::checkmate::CheckmateIfCapture::CallDefense
00011 {
00012 NumEffectState *state;
00013 int depth;
00014 bool result;
00015 void operator()(Position last_to)
00016 {
00017 result = cannotCapture(*state, last_to, depth);
00018 }
00019 };
00020
00021
00022 bool osl::checkmate::
00023 CheckmateIfCapture::effectiveAttack(NumEffectState& state, Move move, int depth)
00024 {
00025 CallDefense defense = { &state, depth, false};
00026 ApplyMoveOfTurn::doUndoMove(state, move, defense);
00027 return defense.result;
00028 }
00029
00030 bool osl::checkmate::
00031 CheckmateIfCapture::cannotCapture(NumEffectState& state,
00032 Position last_to, int depth)
00033 {
00034 if (EffectUtil::isKingInCheck(alt(state.getTurn()), state))
00035 return false;
00036
00037 using namespace move_generator;
00038 using namespace move_action;
00039 MoveVector moves;
00040 Store store(moves);
00041 GenerateCapture::generate(state.getTurn(), state, last_to, store);
00042 if (moves.empty())
00043 return false;
00044
00045 FixedDepthSearcher searcher(state);
00046 for (MoveVector::const_iterator p=moves.begin(); p!=moves.end(); ++p)
00047 {
00048 const bool checkmate
00049 = searcher.hasEscapeByMoveOfTurn(*p, depth).isCheckmateSuccess();
00050 if (! checkmate)
00051 return false;
00052 }
00053
00054 return true;
00055 }
00056
00057
00058
00059
00060
00061