알파 베타가있는 Reversi 게임을 제작하고 있는데 알파 베타에 도움이 필요합니다. 문제는 컴퓨터가 보드의 아래쪽에있는 사각형 중 하나를 계속 선택한다는 것입니다. 컴퓨터가 가능한 동작 목록을 가지고 있습니다 (아래 코드에서 볼 수 있듯이). 컴퓨터가 거의 항상 해당 목록의 마지막 동작 중 하나 또는 마지막 동작을 선택하고 있습니다. 이 아니더라도. 내 평가 기능은 간단합니다 : 검은 조각에서 흰색 조각 빼기. 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());
}