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