1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
template<class T>
float MiniMax_Branch<T>::GetValue(int Depth, float Alpha, float Beta)
{
if ( Depth >= MaxDepth )
return StaticEvaluation(Representative, Type);
else
{
if ( Type == MINIMAX_MAX )
{
while ( GenerateMove(this, Children.size()) )
{
Alpha = Max( Alpha, Children.back()->GetValue(Depth+1,Alpha,Beta) );
if ( Beta <= Alpha )
break;
}
if ( Children.size() == 0 )
return StaticEvaluation(Representative, Type);
return Alpha;
}
else
{
while ( GenerateMove(this, Children.size()) )
{
Beta = Min( Beta, Children.back()->GetValue(Depth+1,Alpha,Beta) );
if ( Beta <= Alpha )
break;
}
if ( Children.size() == 0 )
return StaticEvaluation(Representative, Type);
return Beta;
}
}
}
template<class T>
T* MiniMax_Branch<T>::GetChoice()
{
while ( GenerateMove(this,Children.size()) ) ///Make all the children for the origin node
NULL;
struct
{
unsigned short Index;
float Value;
} BestChild;
BestChild.Index = 0;
BestChild.Value = Children[0]->GetValue(1);
for ( int i = 1; i < Children.size(); i++ )
{
float Value = Children[i]->GetValue(1);
if ( Value > BestChild.Value && Type == MINIMAX_MAX )
{
BestChild.Index = i;
BestChild.Value = Value;
}
else if ( Value < BestChild.Value && Type == MINIMAX_MINI )
{
BestChild.Index = i;
BestChild.Value = Value;
}
}
return Children[BestChild.Index]->Representative;
}
|