00001 #include "osl/checkmate/fixedDepthSolverExt.h"
00002 #include "osl/checkmate/fixedDepthSearcher.tcc"
00003 #include "osl/checkmate/proofPieces.h"
00004 #include "osl/checkmate/proofNumberTable.h"
00005
00006 struct osl::checkmate::FixedDepthSolverExt::SetProofPieces
00007 {
00008 static void setAttackLeaf(Move best_move, PieceStand& proof_pieces) {
00009 proof_pieces = PieceStand();
00010 if (best_move.isDrop())
00011 proof_pieces.add(best_move.ptype());
00012 }
00013 static void attack(Move best_move, PieceStand stand, PieceStand& proof_pieces) {
00014 proof_pieces = ProofPieces::attack(proof_pieces, best_move, stand);
00015 }
00016 static void setLeaf(const NumEffectState& state, Player P, PieceStand stand, PieceStand& proof_pieces) {
00017 proof_pieces = ProofPieces::leaf(state, P, stand);
00018 }
00019 static void clear(PieceStand& proof_pieces) {
00020 proof_pieces = PieceStand();
00021 }
00022 static void updateMax(PieceStand child, PieceStand& proof_pieces) {
00023 proof_pieces = proof_pieces.max(child);
00024 }
00025 static void addMonopolizedPieces(const NumEffectState& state, Player P,
00026 PieceStand stand, PieceStand& proof_pieces) {
00027 ProofPiecesUtil::addMonopolizedPieces(state, P, stand, proof_pieces);
00028 }
00029 static ProofDisproof attackEstimation(const NumEffectState& state, Player P, King8Info info) {
00030 auto target_king = state.kingSquare(alt(P));
00031 const King8Info info_modified
00032 = Edge_Table.resetEdgeFromLiberty(alt(P), target_king, info);
00033 return Proof_Number_Table.attackEstimation(state, P, info_modified, target_king);
00034 }
00035 };
00036
00037 osl::checkmate::FixedDepthSolverExt::FixedDepthSolverExt()
00038 {
00039 }
00040
00041 osl::checkmate::FixedDepthSolverExt::
00042 FixedDepthSolverExt(NumEffectState& s) : FixedDepthSearcher(s)
00043 {
00044 }
00045
00046 template <osl::Player P>
00047 const osl::checkmate::ProofDisproof
00048 osl::checkmate::FixedDepthSolverExt::
00049 hasEscapeByMove(Move next_move, int depth, Move& check_move,
00050 PieceStand& proof_pieces)
00051 {
00052 typedef FixedDefenseHelper<P,SetProofPieces,true> helper_t;
00053 proof_pieces = PieceStand();
00054 ProofDisproof pdp;
00055 helper_t helper(*this, depth+1, pdp, proof_pieces);
00056 state->makeUnmakeMove(Player2Type<alt(P)>(),next_move,helper);
00057 check_move = helper.best_move;
00058 return pdp;
00059 }
00060
00061 const osl::checkmate::ProofDisproof
00062 osl::checkmate::FixedDepthSolverExt::
00063 hasCheckmateMoveOfTurn(int depth, Move& best_move, PieceStand& proof_pieces)
00064 {
00065 if (state->turn() == BLACK)
00066 return hasCheckmateMove<BLACK>(depth, best_move, proof_pieces);
00067 else
00068 return hasCheckmateMove<WHITE>(depth, best_move, proof_pieces);
00069 }
00070
00071 const osl::checkmate::ProofDisproof
00072 osl::checkmate::FixedDepthSolverExt::
00073 hasCheckmateWithGuideOfTurn(int depth, Move& guide, PieceStand& proof_pieces)
00074 {
00075 if (state->turn() == BLACK)
00076 return hasCheckmateWithGuide<BLACK>(depth, guide, proof_pieces);
00077 else
00078 return hasCheckmateWithGuide<WHITE>(depth, guide, proof_pieces);
00079 }
00080
00081 const osl::checkmate::ProofDisproof
00082 osl::checkmate::FixedDepthSolverExt::
00083 hasEscapeByMoveOfTurn(Move next_move, int depth,
00084 Move& check_move, PieceStand& proof_pieces)
00085 {
00086 if (state->turn() == BLACK)
00087 return hasEscapeByMove<WHITE>(next_move, depth, check_move, proof_pieces);
00088 else
00089 return hasEscapeByMove<BLACK>(next_move, depth, check_move, proof_pieces);
00090 }
00091
00092 template <osl::Player P>
00093 const osl::checkmate::ProofDisproof
00094 osl::checkmate::FixedDepthSolverExt::
00095 hasCheckmateWithGuide(int depth, Move& guide, PieceStand& proof_pieces)
00096 {
00097 assert(guide.isNormal());
00098 if (! guide.isDrop())
00099 {
00100 const Piece p=state->pieceOnBoard(guide.to());
00101 if (!p.isPtype<KING>())
00102 guide=guide.newCapture(p);
00103 }
00104 if (state->template isAlmostValidMove<false>(guide)
00105 && move_classifier::Check<P>
00106 ::isMember(*state, guide.ptype(), guide.from(), guide.to()))
00107 return attack<P,SetProofPieces,true>(depth, guide, proof_pieces);
00108 return attack<P,SetProofPieces,false>(depth, guide, proof_pieces);
00109 }
00110
00111 template <osl::Player P>
00112 const osl::checkmate::ProofDisproof osl::checkmate::
00113 FixedDepthSolverExt::hasCheckmateMove(int depth, Move& best_move,
00114 PieceStand& proof_pieces) {
00115 return attack<P,SetProofPieces,false>(depth, best_move, proof_pieces);
00116 }
00117
00118 template <osl::Player P>
00119 const osl::checkmate::ProofDisproof osl::checkmate::
00120 FixedDepthSolverExt::hasEscapeMove(Move last_move,int depth,
00121 PieceStand& proof_pieces) {
00122 return defense<P,SetProofPieces>(last_move, depth, proof_pieces);
00123 }
00124
00125 namespace osl
00126 {
00127 template const checkmate::ProofDisproof checkmate::FixedDepthSolverExt::hasCheckmateMove<BLACK>(int, Move&, PieceStand&);
00128 template const checkmate::ProofDisproof checkmate::FixedDepthSolverExt::hasCheckmateMove<WHITE>(int, Move&, PieceStand&);
00129 template const checkmate::ProofDisproof checkmate::FixedDepthSolverExt::hasEscapeMove<BLACK>(Move, int, PieceStand&);
00130 template const checkmate::ProofDisproof checkmate::FixedDepthSolverExt::hasEscapeMove<WHITE>(Move, int, PieceStand&);
00131 template const checkmate::ProofDisproof checkmate::FixedDepthSolverExt::hasEscapeByMove<BLACK>(Move, int, Move&, PieceStand&);
00132 template const checkmate::ProofDisproof checkmate::FixedDepthSolverExt::hasEscapeByMove<WHITE>(Move, int, Move&, PieceStand&);
00133 }
00134
00135
00136
00137
00138