00001
00002
00003 #ifndef OSL_DUALDFPN_H
00004 #define OSL_DUALDFPN_H
00005 #include "osl/numEffectState.h"
00006 #include "osl/checkmate/proofDisproof.h"
00007 #include "osl/hashKey.h"
00008 #include "osl/pathEncoding.h"
00009 #include "osl/container/moveStack.h"
00010 #include <memory>
00011 #include <cstddef>
00012 #include <limits>
00013
00014 #ifdef OSL_SMP
00015 # ifndef OSL_DFPN_SMP
00016 # define OSL_DFPN_SMP
00017 # endif
00018 #endif
00019
00020 namespace osl
00021 {
00022 class RepetitionCounter;
00023 namespace checkmate
00024 {
00025 class Dfpn;
00026 class DfpnTable;
00028 class DualDfpn
00029 {
00030 struct Shared;
00031 struct Local;
00032 struct OraclePool;
00033 std::shared_ptr<Shared> shared;
00034 std::unique_ptr<Local> local;
00035 public:
00036 explicit DualDfpn(uint64_t ignored=std::numeric_limits<uint64_t>::max());
00037 DualDfpn(const DualDfpn& src);
00038 ~DualDfpn();
00039
00040 void setRootPlayer(Player);
00041 template <Player P>
00042 ProofDisproof findProof(int node_limit, const NumEffectState& state,
00043 const HashKey& key, const PathEncoding& path,
00044 Move& best_move, Move last_move=Move::INVALID());
00050 template <Player P>
00051 bool isWinningState(int node_limit, const NumEffectState& state,
00052 const HashKey& key, const PathEncoding& path,
00053 Move& best_move, Move last_move=Move::INVALID())
00054 {
00055 return findProof(node_limit, state, key, path, best_move, last_move)
00056 .isCheckmateSuccess();
00057 }
00058 bool isWinningState(int node_limit, const NumEffectState& state,
00059 const HashKey& key, const PathEncoding& path,
00060 Move& best_move, Move last_move=Move::INVALID());
00061 ProofDisproof findProof(int node_limit, const NumEffectState& state,
00062 const HashKey& key, const PathEncoding& path,
00063 Move& best_move, Move last_move=Move::INVALID());
00064 #ifdef OSL_DFPN_SMP
00065
00069 template <Player P>
00070 bool isWinningStateParallel(int node_limit, const NumEffectState& state,
00071 const HashKey& key, const PathEncoding& path,
00072 Move& best_move, Move last_move=Move::INVALID());
00073 bool isWinningStateParallel(int node_limit, const NumEffectState& state,
00074 const HashKey& key, const PathEncoding& path,
00075 Move& best_move, Move last_move=Move::INVALID());
00076 #endif
00077 template <Player P>
00078 bool isLosingState(int node_limit, const NumEffectState& state,
00079 const HashKey& key, const PathEncoding& path,
00080 Move last_move=Move::INVALID());
00081 bool isLosingState(int node_limit, const NumEffectState& state,
00082 const HashKey& key, const PathEncoding& path,
00083 Move last_move=Move::INVALID());
00084
00085 void runGC(bool verbose=false, size_t memory_use_ratio_1000=0);
00086
00087
00088 void setVerbose(int level=1);
00089 int distance(Player attack, const HashKey& key);
00090 size_t mainNodeCount() const;
00091 size_t totalNodeCount() const;
00092 void writeRootHistory(const RepetitionCounter& counter,
00093 const MoveStack& moves,
00094 const SimpleState& state, Player attack);
00095 const DfpnTable& table(Player) const;
00096 private:
00097 Dfpn& prepareDfpn(Player attack);
00098 Dfpn& prepareDfpnSmall(Player attack);
00099 };
00100 }
00101 using checkmate::DualDfpn;
00102 }
00103
00104 #endif
00105
00106
00107
00108