アルファベータ版のReversiゲームをビルドしています。私はアルファベータ版であなたの助けが必要です。 問題は、コンピュータがボードの下側にある四角形の1つを選択し続けることです。私はコンピュータの可能な移動のリストを持っています(下のコードで見ることができます)。つまり、コンピュータがほぼ常にそのリストの最後の移動の1つを選択しています。。私の評価機能は簡単です:黒い部分から白い部分を引いたものです。 BTW:深さ= 1でうまく動作しますが、深さ= 3で動作する必要があります。アルファベータプルーニング
public int AlphaBeta(int depth,int turn,TreeNode root,int alpha,int beta)
{
if(depth==0)
return evaluationFunc(turn,turns,root.board,root);
else
{
buildSons(turn,root);
TreeNode head = generateList(root.sons);
return executeCheckTheSons2(depth,turn,head,alpha,beta);
}
}
public int executeCheckTheSons2(int depth,int turn,TreeNode head,int alpha,int beta)
{
int score;
if(turn==1)
{
while(head!=null)
{
head.board=simulateTheMove(head.board,head.getX(),head.getY(),turn);
score=AlphaBeta(depth-1,turn*-1,head,alpha,beta);
if(score > alpha)
{
alpha=score;
setMove(head);
}
if(alpha >= beta)
return alpha;
head=head.next;
}
return alpha;
}
else
{
while(head!=null)
{
head.board=simulateTheMove(head.board,head.getX(),head.getY(),turn);
score=AlphaBeta(depth-1,turn*-1,head,alpha,beta);
if(score<beta)
{
beta=score;
setMove(head);
}
if(alpha >= beta)
return beta;
head=head.next;
}
return beta;
}
}
public void setMove(TreeNode root)
{
while(root.father.father!=null)
root=root.father;
pnt.setX(root.getX());
pnt.setY(root.getY());
}