00001 #ifndef _CHECKMATE_SEARHCER_H
00002 #define _CHECKMATE_SEARHCER_H
00003 #include "osl/checkmate/proofDisproof.h"
00004 #include "osl/checkmate/checkHashTable.h"
00005 #include "osl/checkmate/checkHashRecord.h"
00006 #include "osl/checkmate/fixedDepthSearcher.h"
00007 #include "osl/state/numEffectState.h"
00008 #include "osl/hash/hashKey.h"
00009 #include "osl/pathEncoding.h"
00010 #include "osl/move.h"
00011 #include <cstddef>
00012
00013 #ifndef CHECKMATE_DEFAULT_TOTAL_NODE_LIMIT
00014 #define CHECKMATE_DEFAULT_TOTAL_NODE_LIMIT 5000000
00015
00016
00017 #endif
00018
00019 namespace osl
00020 {
00021 namespace checkmate
00022 {
00023 class CheckMove;
00024 class CheckMoveList;
00025 class LibertyEstimator;
00026 class PieceCost;
00037 template<class Table=CheckHashTable,
00038 class HEstimator=LibertyEstimator, class CostEstimator=PieceCost>
00039 class CheckmateSearcher
00040 {
00041 public:
00042 typedef NumEffectState state_t;
00043 typedef Table table_t;
00044 private:
00045 state_t *state;
00046 Table& table;
00047 FixedDepthSearcher fixed_searcher;
00048 HashKey key;
00049 PathEncoding path;
00050 int depth;
00052 size_t node_count;
00054 size_t search_node_limit;
00056 size_t total_node_count;
00058 const size_t total_node_limit;
00059 bool verbose_destructor;
00060 const Player attacker;
00061 void clearNodeCount() { total_node_count+=node_count; node_count=0; }
00062 public:
00066 CheckmateSearcher(Player attacker, Table& t,
00067 size_t limit=CHECKMATE_DEFAULT_TOTAL_NODE_LIMIT);
00068 ~CheckmateSearcher();
00069 size_t totalNodeCount() const { return total_node_count; }
00070 size_t totalNodeLimit() const { return total_node_limit; }
00071 bool verbose() const { return verbose_destructor; }
00072 void setVerbose(bool verbose=true) { verbose_destructor = verbose; }
00079 template <Player P>
00080 const ProofDisproof
00081 hasCheckmateMove(state_t& state,
00082 const HashKey& key, const PathEncoding& path,
00083 size_t search_node_limit, Move& best_move);
00084 const ProofDisproof
00085 hasCheckmateMove(state_t& state, const HashKey& key,
00086 const PathEncoding& path, size_t limit, Move& best_move)
00087 {
00088 if (attacker == BLACK)
00089 return hasCheckmateMove<BLACK>(state, key, path, limit, best_move);
00090 else
00091 return hasCheckmateMove<WHITE>(state, key, path, limit, best_move);
00092 }
00102 template <Player P>
00103 const ProofDisproof
00104 hasEscapeMove(state_t& state, const HashKey&, const PathEncoding& path,
00105 size_t search_node_limit, Move last_move);
00106 const ProofDisproof
00107 hasEscapeMove(state_t& state,
00108 const HashKey& key, const PathEncoding& path,
00109 size_t limit, Move last_move)
00110 {
00111 if (attacker == BLACK)
00112 return hasEscapeMove<BLACK>(state, key, path, limit, last_move);
00113 else
00114 return hasEscapeMove<WHITE>(state, key, path, limit, last_move);
00115 }
00125 template <Player P>
00126 void attack(unsigned int proofLimit, unsigned int disproofLimit,
00127 CheckHashRecord *parent, CheckHashRecord *record);
00136 template <Player P>
00137 void defense(unsigned int proofLimit, unsigned int disproofLimit,
00138 CheckHashRecord *parent, CheckHashRecord *record);
00139
00140 const table_t& getTable() const { return table; }
00141 private:
00147 template <Player P>
00148 bool setUpAttackNode(CheckHashRecord *record);
00154 template <Player P>
00155 bool setUpDefenseNode(CheckHashRecord *record);
00156
00157 bool exceedNodeCount(unsigned int futureCost) const;
00158 static bool exceedRootTolerance(unsigned int proofNumber, unsigned int disproofNumber,
00159 unsigned int continuousNoExpandLoop);
00160 };
00161 }
00162 using checkmate::CheckmateSearcher;
00163 }
00164 #endif // _CHECKMATE_SEARHCER_H
00165
00166
00167
00168