나는 네 개의 게임에 연결하는 minimax 알고리즘을 구현하려고합니다. 저는 evaluation-function으로 끝났습니다. 그리고 알고리즘 함수로 끝났습니다.네 가지 연결 - 평가 - C의
"마지막"문제에 대한 해결책을 찾을 수 없습니다. 여기 내 기능은 다음
void minimax(field f){
int i;
field c;
convert_1D_to_2D(f, c);
for(i=0;i<COLS;i++) {
if(can_throw(c, i) == 0) {
throw(f, i);
convert_1D_to_2D(f, c);
if((is_winner(c) == 0) && (is_board_full(f) == 0)) { //no winner, board not full
minimax(f);
}
else if(is_winner(c) == 1) { //there is a winner
evaluate_turn(f);
//compare evaluation
undo_turn(f);
}
else if(is_winner(c) == 0 && (is_board_full(f) == 1)) { //no winner, board full
evaluate_turn(f);
//compare evaluation
undo_turn(f);
}
}
}
필드 F [0] 깊이이고, 다른 요소가되는 열이 발생하고 저장 F [COLS * ROWS + 1]과 배열이다. 은 "C"-board는 플레이어 플레이어 1 무료 0, 1, 2로 "그래픽"보드를 나타내는 2
static int evaluate_turn(field f) {
field c;
convert_1D_to_2D(f, c);
if (((f[0] % 2) == 1) && (current_player == 1) && (is_winner(c) == 1)) { //player 1 won, max for him || +1
return 1;
}
else if (((f[0] % 2) == 2) && (current_player == 2) && (is_winner(c) == 1)) { //player 2 won, max for him || +1
return 1;
}
if (((f[0] % 2) == 1) && (current_player == 2) && (is_winner(c) == 1)) { //player 2 won, counting for 1 || -1
return -1;
}
else if (((f[0] % 2) == 2) && (current_player == 1) && (is_winner(c) == 1)) { //player 1 won, counting for 2 || -1
return -1;
}
else if ((is_board_full(f) == 1) && (is_winner(c) == 0)) { //draw || 0
return 0;
}
그래서 내 문제는 내가 깨끗한 솔루션 생각하지 수있다 평가를 위에서 아래로 비교하십시오. 필자는 새로운 데이터 구조를 도입 할 필요가 없다고 생각합니다. 마치 솔루션이 내 앞에 있지만 나는 그것을 잡지 못합니다.
재귀의 "뒤로 돌아 가기"평가를 비교할 수 있습니까? 그렇다면 어떻게?
아니면 좀 더 복잡한 새로운 것을 소개해야합니까? 아니면 뭔가 완전히 사라 졌을까요?
감사합니다.