00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef SG_PROBCUT_H
00012 #define SG_PROBCUT_H
00013
00014 #include "SgArray.h"
00015 #include "SgBlackWhite.h"
00016 #include "SgMove.h"
00017 #include "SgSearch.h"
00018 #include "SgStack.h"
00019 #include "SgVector.h"
00020
00021
00022
00023 class SgProbCut
00024 {
00025 public:
00026 static const int MAX_PROBCUT = 20;
00027
00028 SgProbCut();
00029
00030 struct Cutoff {
00031 float a, b, sigma;
00032 int shallow, deep;
00033
00034 Cutoff() : shallow(-1), deep(-1) {}
00035 };
00036
00037 void AddCutoff(const Cutoff &c);
00038
00039 bool GetCutoff(int deep, int index, Cutoff &cutoff);
00040
00041 float GetThreshold() const;
00042
00043 bool IsEnabled() const;
00044
00045 bool ProbCut(SgSearch& search, int depth, int alpha, int beta,
00046 SgSearchStack& moveStack,
00047 bool* isExactValue, int* value);
00048
00049 void SetEnabled(bool flag);
00050
00051 void SetThreshold(float t);
00052
00053 private:
00054 float m_threshold;
00055 bool m_enabled;
00056
00057 SgArray<SgArray<Cutoff, MAX_PROBCUT+1>, MAX_PROBCUT+1> m_cutoffs;
00058 SgArray<int, MAX_PROBCUT+1> m_cutoff_sizes;
00059 };
00060
00061 inline SgProbCut::SgProbCut()
00062 {
00063 m_threshold = 1.0;
00064 m_enabled = false;
00065 for (int i = 0; i < MAX_PROBCUT+1; ++i) m_cutoff_sizes[i] = 0;
00066 }
00067
00068 inline void SgProbCut::AddCutoff(const Cutoff &c)
00069 {
00070 int i = m_cutoff_sizes[c.deep];
00071 m_cutoffs[c.deep][i] = c;
00072 ++m_cutoff_sizes[c.deep];
00073 }
00074
00075 inline bool SgProbCut::GetCutoff(int deep, int index, Cutoff &cutoff)
00076 {
00077 if (deep > MAX_PROBCUT) return false;
00078 if (index >= m_cutoff_sizes[deep]) return false;
00079 cutoff = m_cutoffs[deep][index];
00080 return true;
00081 }
00082
00083 inline void SgProbCut::SetThreshold(float t)
00084 {
00085 m_threshold = t;
00086 }
00087
00088 inline float SgProbCut::GetThreshold() const
00089 {
00090 return m_threshold;
00091 }
00092
00093 inline void SgProbCut::SetEnabled(bool flag)
00094 {
00095 m_enabled = flag;
00096 }
00097
00098 inline bool SgProbCut::IsEnabled() const
00099 {
00100 return m_enabled;
00101 }
00102
00103
00104
00105 #endif // SG_PROBCUT_H