터미널 케이스가 이기고, 손실되고 그려지는 미니 맥스 알고리즘을 사용하여 tic-tac-toe를 이해합니다 - 10,0, -10.maxconnect4 게임의 터미널 케이스는 무엇이 될까요?
어떤 프로그램이이기거나, 느슨하거나 그릴 때 프로그램이 종료됩니다. 4 개의 게임을 연결하면 3 개의 터미널 상태가 아니라 게임 종료 후 점수 판이 아닌 평가 함수에서 터미널 케이스를 어떻게 결정합니까? 평가 기능을 구현하는 방법은 무엇입니까?
int minimax(char board[3][3], int depth, bool isMax)
{
int score = evaluate(board);
// If Maximizer has won the game return his/her
// evaluated score
if (score == 10)
return score;
// If Minimizer has won the game return his/her
// evaluated score
if (score == -10)
return score;
// If there are no more moves and no winner then
// it is a tie
if (isMovesLeft(board)==false)
return 0;
// If this maximizer's move
if (isMax)
{
int best = -1000;
// Traverse all cells
for (int i = 0; i<3; i++)
{
for (int j = 0; j<3; j++)
{
// Check if cell is empty
if (board[i][j]=='_')
{
// Make the move
board[i][j] = player;
// Call minimax recursively and choose
// the maximum value
best = max(best,
minimax(board, depth+1, !isMax));
// Undo the move
board[i][j] = '_';
}
}
}
return best;
}
// If this minimizer's move
else
{
int best = 1000;
// Traverse all cells
for (int i = 0; i<3; i++)
{
for (int j = 0; j<3; j++)
{
// Check if cell is empty
if (board[i][j]=='_')
{
// Make the move
board[i][j] = opponent;
// Call minimax recursively and choose
// the minimum value
best = min(best,
minimax(board, depth+1, !isMax));
// Undo the move
board[i][j] = '_';
}
}
}
return best;
}
}
그러나 connect4에 대한 , 어떻게 평가 함수를 계산합니까 그것은 (보드가 꽉 찬 경우를 제외하고) 단자의 경우를 정의하는 방법?
대부분의 게임에서와 마찬가지로 검색 공간을 완전히 탐색 할 수 없다는 가정하에이 점수와 비슷한 평가 함수가 수행됩니다. 그래서 스코어 값은, 어떤 깊이에서 멈추었을 때, 끝 상태에서는 -1이고, 그렇지 않다면 ([1, -1] 사이에서는) 함수입니다. – sascha