Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "SgSystem.h"
00007 #include "SgProbCut.h"
00008
00009 #include "SgMath.h"
00010 #include "SgSearch.h"
00011
00012
00013
00014 bool SgProbCut::ProbCut(SgSearch& search, int depth, int alpha, int beta,
00015 SgSearchStack& moveStack, bool* isExactValue,
00016 int* value)
00017 {
00018 SG_ASSERT(IsEnabled());
00019 SetEnabled(false);
00020
00021 Cutoff c;
00022 int index = 0;
00023 while (GetCutoff(depth / SgSearch::DEPTH_UNIT, index++, c))
00024 {
00025 SgSearchStack newStack;
00026 bool isExact;
00027 float threshold = GetThreshold();
00028
00029 if (beta < SgSearch::SG_INFINITY-1)
00030 {
00031 float b = (+threshold * c.sigma + float(beta) - c.b) / c.a;
00032 int bound = SgMath::RoundToInt(b);
00033 int res = search.SearchEngine(c.shallow * SgSearch::DEPTH_UNIT,
00034 bound-1, bound, newStack, &isExact);
00035 if (res >= bound)
00036 {
00037 SetEnabled(true);
00038 newStack.PushAll(moveStack);
00039 newStack.SwapWith(moveStack);
00040 *isExactValue = isExact;
00041 *value = beta;
00042 return true;
00043 }
00044 }
00045
00046 if (alpha > -SgSearch::SG_INFINITY + 1)
00047 {
00048 float b = (-threshold * c.sigma + float(alpha) - c.b) / c.a;
00049 int bound = SgMath::RoundToInt(b);
00050 int res = search.SearchEngine(c.shallow * SgSearch::DEPTH_UNIT,
00051 bound, bound+1, newStack, &isExact);
00052
00053 if (res <= bound)
00054 {
00055 SetEnabled(true);
00056 newStack.PushAll(moveStack);
00057 newStack.SwapWith(moveStack);
00058 *isExactValue = isExact;
00059 *value = alpha;
00060 return true;
00061 }
00062 }
00063 }
00064 SetEnabled(true);
00065 return false;
00066 }
00067
00068