00001
00002
00003 #ifndef _CHECKMATE_FIXED_DEPTH_SERCHER2_H
00004 #define _CHECKMATE_FIXED_DEPTH_SERCHER2_H
00005 #include "osl/checkmate/proofDisproof.h"
00006 #include "osl/state/numEffectState.h"
00007 #include "osl/move.h"
00008 #include "osl/pieceStand.h"
00009 #include "osl/misc/carray.h"
00010 #include "osl/misc/align16New.h"
00011
00012 namespace osl
00013 {
00014 class PieceStand;
00015 namespace container
00016 {
00017 class MoveVector;
00018 }
00019 namespace checkmate
00020 {
00029 class FixedDepthSearcher2
00030 #if OSL_WORDSIZE == 32
00031 : public misc::Align16New
00032 #endif
00033 {
00034 private:
00035 static const int MAXDEPTH=16;
00036 NumEffectState *original_state;
00037 CArray<NumEffectState,MAXDEPTH> states;
00038 int count;
00039 public:
00040 FixedDepthSearcher2() : original_state(0), count(0)
00041 {
00042 }
00043 explicit FixedDepthSearcher2(NumEffectState& s)
00044 : original_state(&s), count(0)
00045 {
00046 }
00047 void setState(NumEffectState& s)
00048 {
00049 original_state = &s;
00050 }
00051 private:
00052 void addCount()
00053 {
00054 count++;
00055 }
00056 public:
00057 int getCount() const
00058 {
00059 return count;
00060 }
00061 public:
00062
00063 template <Player P, bool SetPieces, bool HasGuide>
00064 const ProofDisproof attack(int depth, Move& best_move, PieceStand& proof_pieces);
00065 template <Player P, bool SetPieces, bool HasGuide>
00066 const ProofDisproof attackMayUnsafe(int depth, Move& best_move, PieceStand& proof_pieces);
00067 template <Player P, bool SetPieces>
00068 const ProofDisproof defense(Move last_move,int depth,
00069 PieceStand& proof_pieces);
00070 private:
00074 template <Player P, bool SetPieces>
00075 const ProofDisproof defenseEstimation(int depth,Move last_move, PieceStand& proof_pieces,
00076 Piece attacker_piece,
00077 Square target_position) const;
00078 public:
00083 template <Player P>
00084 const ProofDisproof hasCheckmateMove(int depth, Move& best_move,
00085 PieceStand& proof_pieces)
00086 {
00087 states[depth].copyFrom(*original_state);
00088 return attack<P,true,false>(depth, best_move, proof_pieces);
00089 }
00094 template <Player P>
00095 const ProofDisproof hasCheckmateWithGuide(int depth, Move& guide,
00096 PieceStand& proof_pieces);
00097 template <Player P>
00098 const ProofDisproof hasCheckmateMove(int depth,Move& best_move)
00099 {
00100 PieceStand proof_pieces;
00101 states[depth].copyFrom(*original_state);
00102 return attack<P,false,false>(depth, best_move, proof_pieces);
00103 }
00104 template <Player P>
00105 const ProofDisproof hasCheckmateMove(int depth)
00106 {
00107 Move checkmate_move;
00108 return hasCheckmateMove<P>(depth, checkmate_move);
00109 }
00110
00118 template <Player P>
00119 const ProofDisproof hasEscapeMove(Move last_move,int depth,
00120 PieceStand& proof_pieces)
00121 {
00122 return defense<P,true>(last_move, depth, proof_pieces);
00123 }
00124 template <Player P>
00125 const ProofDisproof hasEscapeMove(Move last_move,int depth)
00126 {
00127 PieceStand proof_pieces;
00128 return defense<P,false>(last_move, depth, proof_pieces);
00129 }
00135 template <Player P>
00136 const ProofDisproof hasEscapeByMove(Move next_move, int depth,
00137 Move& check_move,
00138 PieceStand& proof_pieces);
00139 template <Player P>
00140 const ProofDisproof hasEscapeByMove(Move next_move, int depth);
00141
00142 const ProofDisproof hasCheckmateMoveOfTurn(int depth,Move& best_move);
00143 const ProofDisproof hasCheckmateMoveOfTurn(int depth,Move& best_move,
00144 PieceStand& proof_pieces);
00145 const ProofDisproof hasCheckmateWithGuideOfTurn(int depth, Move& guide,
00146 PieceStand& proof_pieces);
00147 const ProofDisproof hasEscapeMoveOfTurn(Move last_move,int depth);
00148 const ProofDisproof hasEscapeByMoveOfTurn(Move next_move, int depth,
00149 Move& check_move,
00150 PieceStand& proof_pieces);
00151 const ProofDisproof hasEscapeByMoveOfTurn(Move next_move, int depth);
00152
00156 template <Player Defense>
00157 void generateBlockingWhenLiberty0(int depth,Piece defense_king, Square attack_from,
00158 container::MoveVector& moves) const;
00159 template <Player Defense>
00160 int blockEstimation(Square attack_from, Square defense_king) const;
00161 };
00162 }
00163 }
00164
00165 #endif
00166
00167
00168
00169