Professional Documents
Culture Documents
Sathaye College: Practical No: 7
Sathaye College: Practical No: 7
Practical No: 7
Aim: Optimize the search strategy for the suggested problem using:
i. Mini-Max Algorithm.
ii. Alpha Beta Pruning.
i. Mini-Max Algorithm
CODE:
import java.io.*;
class MinMax
static int minimax(int depth, int nodeIndex, boolean isMax,int scores[], int h)
if (depth == h)
return scores[nodeIndex];
if (isMax)
else
BHUPENDRA MISHRA
SATHAYE COLLEGE
Intelligent Systems M.Sc.IT Part II SEM IV
// Driver code
int no = Integer.parseInt(br.readLine());
for(int i=0;i<no;i++)
scores[i] = Integer.parseInt(br.readLine());
int n = scores.length;
int h = log2(n);
BHUPENDRA MISHRA
SATHAYE COLLEGE
Intelligent Systems M.Sc.IT Part II SEM IV
OUTPUT :
BHUPENDRA MISHRA
SATHAYE COLLEGE
Intelligent Systems M.Sc.IT Part II SEM IV
CODE :
import java.io.*;
class AlphaBeta
static int minimax(int depth, int nodeIndex, Boolean maximizingPlayer,int values[], int alpha, int
beta)
if (depth == 3)
return values[nodeIndex];
if (maximizingPlayer)
break;
return best;
BHUPENDRA MISHRA
SATHAYE COLLEGE
Intelligent Systems M.Sc.IT Part II SEM IV
else
break;
return best;
// Driver Code
int no = Integer.parseInt(br.readLine());
for(int i=0;i<no;i++)
BHUPENDRA MISHRA
SATHAYE COLLEGE
Intelligent Systems M.Sc.IT Part II SEM IV
values[i] = Integer.parseInt(br.readLine());
//int values[] = { 3, 5, 6, 9, 1, 2, 0, -1 };
OUTPUT :
BHUPENDRA MISHRA