public static int[][] Move(int temp[][],int x,int t) {
if(temp_heigth[x]>0)
{
if(t==1)
temp[temp_heigth[x]-1][x]=1;
else
temp[temp_heigth[x]-1][x]=2;
temp_heigth[x]--;
}
else
{
//System.out.println("Column is full. Try a new column");
}
return temp;
}
public static int AlphaBetaSearch(State state){
state.value = max_value(state,-99999,99999,10);
return state.move;
}
public static int max_value(State state, int alpha, int beta, int depth){
int t_arr[][] =new int[8][8];
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
t_arr[i][j]=state.state[i][j];
}
if (depth==0/* || control_state(t_arr)!= 0*/){
return state.value;
}
for(int c=1;c<9;c++){
State temp=new State();
temp.move=c;
temp.state=Move(t_arr,c-1,2);
temp.value = eva_fun(temp.state);
state.children.add(temp);
}
for (State a: state.children){
state.value = Math.max(state.value , min_value(a, alpha, beta, depth-1));
if (state.value >= beta){
return state.value;
}
alpha = Math.max(alpha, state.value);
}
return state.value;
}
public static int min_value(State state, int alpha, int beta, int depth){
int t_arr[][] =new int[8][8];
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
t_arr[i][j]=state.state[i][j];
}
if (depth==0 /*|| control_state(t_arr)!= 0*/)
return state.value;
for(int c=1;c<9;c++){
State temp=new State();
temp.move=c;
temp.state=Move(t_arr,c-1,1);
temp.value = eva_fun(temp.state);
state.children.add(temp);
}
for (State a: state.children){
state.value = Math.min(state.value, max_value(a, alpha, beta, depth-1));
if (state.value >= alpha){
return state.value;
}
beta = Math.min(beta, state.value);
}
return state.value;
}