首先要提前感谢。
我正在使用MiniMax制作Checkers游戏。出于某种原因无论如何,每当我尝试运行以下方法时,它总是返回“-1”。这与输入的哪一侧和板上有多少件无关。当然有一些我想念的东西?希望你能帮助我发现它。
MiniMax双返回算法:
public double miniMax(String side, int depth, PlaySpace board)
{
this.board = board;
this.side = side;
this.depth = depth;
ChequersMove[] possibleMoves = null;
possibleMoves = board.getLegalMoves(side);
double a;
if(depth==0 || possibleMoves.length < 1){
a = evaluateState(board);
return a;
}
if(side.equals("A")){
a = -10000;
for(ChequersMove move : possibleMoves){
PlaySpace child = new PlaySpace(board.returnState());
child.setState(board.returnState());
child.moveChequer(move.returnCurrentX(),move.returnCurrentY(),move.returnDestX(),move.returnDestY());
double val = miniMax("B",depth-1,child);
a = Math.max(a,val);
}
return a;
}
else{
a = 10000;
for(ChequersMove move : possibleMoves){
PlaySpace child = new PlaySpace(board.returnState());
child.setState(board.returnState());
child.moveChequer(move.returnCurrentX(),move.returnCurrentY(),move.returnDestX(),move.returnDestY());
double val = miniMax("A",depth-1,child);
a = Math.min(a,val);
}
return a;
}
}
简单的评估功能:
public double evaluateState(PlaySpace board)
{
double eval = 0;
for(int x=0;x<8;x++){
for(int y=0;y<8;y++){
if(board.returnState()[x][y]!=null){
if(board.returnState()[x][y].returnSide().equals("A")){
eval++;
}
else if(board.returnState()[x][y].returnSide().equals("B")){
eval--;
}
}
}
}
return eval;
}
如果我能提供更多可能有帮助的信息,请告诉我。再次,非常感谢,我期待着您的回复!