Need help in code for alpha beta With TT
Posted: Mon Jun 10, 2013 9:22 pm
Hi all. I know that this question was asked before,but it seems that i still don't quite get it..
I have the following alpha beta function (JAVA) ,and also a transposition table with all the necessary methods. but i need some technical help in what to insert to the table and what to get from it when i do a prob. in case of a lower or upper bound (whatever it is...) do i need to change the alpha or the beta only? (not returning the score) and only in an exact value should i use the score as the definite score of the board? i need a step by step instructions on what exactly to do and when.
this is my alpha beta function below,can you please please help me to add the TT part to it?
EDIT: oh..and something strange,even when i tried to save positions with an exact value (when no alpha beta break has accured) i also got strange results for some reason. without the TT on,this alpha beta function works fine,but when i try to incorporate the TT it returned incorrect moves sometimes
public Best chooseMove(boolean side,int alpha,int beta,int depth){
Best myBest = new Best();
Best reply;
if(Board.checkGameOver(newBoard)||depth==0){
Best fakeBest = new Best();
fakeBest.setScore(returnPositionScore(newBoard));
return fakeBest;
}
if(side){
myBest.setScore(alpha);
}
else{
myBest.setScore(beta);
}
ArrayList<Integer>availableMoves = searchAvailableMoves(newBoard);
for(Integer move:availableMoves){
makeMove(move);
reply = chooseMove(!side,alpha,beta,depth-1);
unmakeMove(move);
if(side&&reply.getScore()>myBest.getScore()){
myBest.setMove(move);
myBest.setScore(reply.getScore());
alpha = reply.getScore();
}
else if(!side&&reply.getScore()<myBest.getScore()){
myBest.setMove(move);
myBest.setScore(reply.getScore());
beta = reply.getScore();
}
if(alpha>=beta){
return myBest;
}
}
return myBest;
}
I have the following alpha beta function (JAVA) ,and also a transposition table with all the necessary methods. but i need some technical help in what to insert to the table and what to get from it when i do a prob. in case of a lower or upper bound (whatever it is...) do i need to change the alpha or the beta only? (not returning the score) and only in an exact value should i use the score as the definite score of the board? i need a step by step instructions on what exactly to do and when.
this is my alpha beta function below,can you please please help me to add the TT part to it?
EDIT: oh..and something strange,even when i tried to save positions with an exact value (when no alpha beta break has accured) i also got strange results for some reason. without the TT on,this alpha beta function works fine,but when i try to incorporate the TT it returned incorrect moves sometimes
public Best chooseMove(boolean side,int alpha,int beta,int depth){
Best myBest = new Best();
Best reply;
if(Board.checkGameOver(newBoard)||depth==0){
Best fakeBest = new Best();
fakeBest.setScore(returnPositionScore(newBoard));
return fakeBest;
}
if(side){
myBest.setScore(alpha);
}
else{
myBest.setScore(beta);
}
ArrayList<Integer>availableMoves = searchAvailableMoves(newBoard);
for(Integer move:availableMoves){
makeMove(move);
reply = chooseMove(!side,alpha,beta,depth-1);
unmakeMove(move);
if(side&&reply.getScore()>myBest.getScore()){
myBest.setMove(move);
myBest.setScore(reply.getScore());
alpha = reply.getScore();
}
else if(!side&&reply.getScore()<myBest.getScore()){
myBest.setMove(move);
myBest.setScore(reply.getScore());
beta = reply.getScore();
}
if(alpha>=beta){
return myBest;
}
}
return myBest;
}