Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simulate 5 turn ahead for choose the best current move
- Jogadas *minimax(int tabuleiro[TAM][TAM], int depth, int Player){
- // Copy the board for don't change it
- int i, j, copia[TAM][TAM];
- for(i=0; i<=9; i++){
- for(j=0; j<=9; j++){
- copia[i][j] = tabuleiro[i][j];
- }
- }
- Jogadas *BestMove;
- // If depth is the root, get the first best moves
- if((depth == 0) || (gameover(copia))){
- return BestMove;
- }
- // Simulating the current Player 2 (Computer) move
- if(Player == 2){
- Jogadas *BestValue;
- BestValue->pontuacao = -9999;
- Lista_ia *MovesP2;
- verificar_jogadas_possiveis(tabuleiro, MovesP2, Player);
- Jogadas *tmp = (Jogadas*)malloc(sizeof(Jogadas));
- for(MovesP2->head = tmp; tmp != NULL; tmp = tmp->prox){
- BestMove = minimax(copia, depth - 1, 1);
- if(BestMove->pontuacao > BestValue->pontuacao){
- BestValue = BestMove;
- }
- }
- return BestMove;
- }
- // Simulating the best Player 1 move
- else{
- Jogadas *BestValue;
- BestValue->pontuacao = 9999;
- Lista_ia *MovesP1;
- verificar_jogadas_possiveis(tabuleiro, MovesP1, Player);
- Jogadas *aux = (Jogadas*)malloc(sizeof(Jogadas));
- for(MovesP1->head = aux; aux != NULL; aux = aux->prox){
- BestMove = minimax(copia, depth - 1, 2);
- if(BestMove->pontuacao < BestValue->pontuacao){
- BestValue = BestMove;
- }
- }
- return BestMove;
- }
- }
Add Comment
Please, Sign In to add comment