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