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/fastCopier.h"
00011 #include "osl/misc/align16New.h"
00012
00013 namespace osl
00014 {
00015 class PieceStand;
00016 namespace container
00017 {
00018 class MoveVector;
00019 }
00020 namespace checkmate
00021 {
00030 class FixedDepthSearcher2
00031 #if OSL_WORDSIZE == 32
00032 : public misc::Align16New
00033 #endif
00034 {
00035 static void copyState(NumEffectState *dest,NumEffectState * src){
00036 osl::misc::FastCopier::copy(dest,src);
00037 }
00038 private:
00039 static const int MAXDEPTH=16;
00040 NumEffectState *original_state;
00041 CArray<NumEffectState,MAXDEPTH> states;
00042 int count;
00043 public:
00044 FixedDepthSearcher2() : original_state(0), count(0)
00045 {
00046 }
00047 explicit FixedDepthSearcher2(NumEffectState& s)
00048 : original_state(&s), count(0)
00049 {
00050 }
00051 void setState(NumEffectState& s)
00052 {
00053 original_state = &s;
00054 }
00055 private:
00056 void addCount()
00057 {
00058 count++;
00059 }
00060 public:
00061 int getCount() const
00062 {
00063 return count;
00064 }
00065 public:
00066
00067 template <Player P, bool SetPieces, bool HasGuide>
00068 const ProofDisproof attack(int depth, Move& best_move, PieceStand& proof_pieces);
00069 template <Player P, bool SetPieces, bool HasGuide>
00070 const ProofDisproof attackMayUnsafe(int depth, Move& best_move, PieceStand& proof_pieces);
00071 template <Player P, bool SetPieces>
00072 const ProofDisproof defense(Move last_move,int depth,
00073 PieceStand& proof_pieces);
00074 private:
00078 template <Player P, bool SetPieces>
00079 const ProofDisproof defenseEstimation(int depth,Move last_move, PieceStand& proof_pieces,
00080 Piece attacker_piece,
00081 Position target_position) const;
00082 public:
00087 template <Player P>
00088 const ProofDisproof hasCheckmateMove(int depth, Move& best_move,
00089 PieceStand& proof_pieces)
00090 {
00091 copyState(&states[depth],original_state);
00092 return attack<P,true,false>(depth, best_move, proof_pieces);
00093 }
00098 template <Player P>
00099 const ProofDisproof hasCheckmateWithGuide(int depth, Move& guide,
00100 PieceStand& proof_pieces);
00101 template <Player P>
00102 const ProofDisproof hasCheckmateMove(int depth,Move& best_move)
00103 {
00104 PieceStand proof_pieces;
00105 copyState(&states[depth],original_state);
00106 return attack<P,false,false>(depth, best_move, proof_pieces);
00107 }
00108 template <Player P>
00109 const ProofDisproof hasCheckmateMove(int depth)
00110 {
00111 Move checkmate_move;
00112 return hasCheckmateMove<P>(depth, checkmate_move);
00113 }
00114
00122 template <Player P>
00123 const ProofDisproof hasEscapeMove(Move last_move,int depth,
00124 PieceStand& proof_pieces)
00125 {
00126 return defense<P,true>(last_move, depth, proof_pieces);
00127 }
00128 template <Player P>
00129 const ProofDisproof hasEscapeMove(Move last_move,int depth)
00130 {
00131 PieceStand proof_pieces;
00132 return defense<P,false>(last_move, depth, proof_pieces);
00133 }
00139 template <Player P>
00140 const ProofDisproof hasEscapeByMove(Move next_move, int depth,
00141 Move& check_move,
00142 PieceStand& proof_pieces);
00143 template <Player P>
00144 const ProofDisproof hasEscapeByMove(Move next_move, int depth);
00145
00146 const ProofDisproof hasCheckmateMoveOfTurn(int depth,Move& best_move);
00147 const ProofDisproof hasCheckmateMoveOfTurn(int depth,Move& best_move,
00148 PieceStand& proof_pieces);
00149 const ProofDisproof hasCheckmateWithGuideOfTurn(int depth, Move& guide,
00150 PieceStand& proof_pieces);
00151 const ProofDisproof hasEscapeMoveOfTurn(Move last_move,int depth);
00152 const ProofDisproof hasEscapeByMoveOfTurn(Move next_move, int depth,
00153 Move& check_move,
00154 PieceStand& proof_pieces);
00155 const ProofDisproof hasEscapeByMoveOfTurn(Move next_move, int depth);
00156
00160 template <Player Defense>
00161 void generateBlockingWhenLiberty0(int depth,Piece defense_king, Position attack_from,
00162 container::MoveVector& moves) const;
00163 template <Player Defense>
00164 int blockEstimation(Position attack_from, Position defense_king) const;
00165 };
00166 }
00167 }
00168
00169 #endif
00170
00171
00172
00173