Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

//AlphaBeta Search

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
Int max1=1000,min1=1000;
Int minmax(int depth,int nodeindex,bool maxplayer,int alpha,int beta,int value[])
{
If(depth==3)
Return value[nodeindex];
If(maxplayer)
{
Int best=min1;
For(int i=0;i<2;i++)
{
Int val=minmax(depth+1,nodeindex*2+1,false,alpha,beta,value);
best=max(best,val);
Alpha=max(alpha,best);
If(alpha>=beta)
Break;
}
return best;
}
else
{
Int best =max1;
For (int i=0;i<2;i++)
{
Int val =minmax(depth+1,nodeindex*2+1,true,alpha,beta,value);
best=min(best,val);
beta=min(beta,best);
if(beta<=alpha)
break;
}
return best
}
}
Void main()
{
Int values[]=(3,9,64,5,89,61,2,0,-1);
cout<<”The optimal value of top node is :”<<minmax(0,0,true,min1,max1,values);
getch();
}

Output :

The optimal value of top node is : 9

You might also like