アルファベータでリバーシゲームを構築していますが、アルファベータであなたの助けが必要です。問題は、コンピュータがボードの下側にある正方形の1つを選択し続けることです。私はコンピューターの可能な動きのリストを持っています(以下のコードで見ることができます)。つまり、コンピューターは、最良の動きでなくても、ほとんどの場合、そのリストの最後または最後の動きの1つを選択します。私の評価関数は単純です:黒い部分から白い部分を引いたものです。ところで:それはdepth = 1で正常に動作しますが、depth=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());
}