0

알파 베타 제거 알고리즘을 사용하려고합니다. 나는 프로그램을 작동 시켰어. 알파 또는 베타 값을 선택하기 전에 검색 횟수를 계산해야합니다. 나는 값을 세지 만 카운트 값이 맞는지 확실하지 않습니다.알파 베타 전정 검색 수

int alpha_beta(const int level, const bool player, const Board &board, int alpha, int beta, Move &move) { 
**static int count = 0;** 

if (board.isGameOver() || level == 0) { 
    if (!board.isGameOver()) move = (board.legalMoves())[0]; 
    return (getScore(board)); 
} 

vector<Move> children = board.legalMoves(); 

tempBoard = board; 
permutator(children.begin(), children.end()); 
//cout << count; 
//getchar(); 
if (player == MAX) { 
    for (vector<Move>::iterator it = children.begin(); it != children.end(); it++) { 
     Board child = board.doMove(*it); 
     Move temp; 
     int score = alpha_beta(level - 1, !player, child, alpha, beta, temp); 
     if (score > alpha) { 
      alpha = score; // We have found a better best move 
      move = *it; 
     } 
     if (alpha >= beta) { 
      move = *it; 
      cout << alpha; 
      return alpha; // Beta Cut Off 
      cout << alpha; 
     } 
     count++; 
    } 

    **cout << "alpha count ="<<count;** 
    std::getchar(); 
    return alpha; // This is our best move 

} 
else { 
    for (vector<Move>::iterator it = children.begin(); it != children.end(); it++) { 
     Board child = board.doMove(*it); 
     Move temp; 
     int score = alpha_beta(level - 1, !player, child, alpha, beta, temp); 
     if (score < beta) { 
      beta = score; // Opponent has found a better worse move 
      move = *it; 
     } 
     if (alpha >= beta) { 
      move = *it; 
      cout << beta; 
      return beta; // Alpha Cut Off 
     } 


     count++; 
    } 
    **cout <<" beta count ="<<count;** 
    std::getchar(); 
    return beta; // This is the opponent's best move 
}} 

모든 검색 제안이 검색 횟수에 도움이됩니다.

답변

0

기본적으로 알파 베타 제거는 Minimax의 최적화이므로 Minimax 알고리즘을 먼저 구현해야 할 수도 있습니다. 알파 또는 베타를 선택하기 전에 검색 한 총 잎 수를 얻으려면 Minimax 어쩌면 좋은 선택 일 수 있습니다.

이 경우

, 당신은 당신의 트리 노드

if (board.isGameOver() || level == 0) { 
    count ++; 
    if (!board.isGameOver()) move = (board.legalMoves())[0]; 
    return (getScore(board)); 
} 
에게 남겨에 도달 할 때마다 카운터를 추가해야