Guest User

Untitled

a guest
May 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. // Simulate 5 turn ahead for choose the best current move
  2. Jogadas *minimax(int tabuleiro[TAM][TAM], int depth, int Player){
  3. // Copy the board for don't change it
  4. int i, j, copia[TAM][TAM];
  5. for(i=0; i<=9; i++){
  6. for(j=0; j<=9; j++){
  7. copia[i][j] = tabuleiro[i][j];
  8. }
  9. }
  10. Jogadas *BestMove;
  11. // If depth is the root, get the first best moves
  12. if((depth == 0) || (gameover(copia))){
  13. return BestMove;
  14. }
  15. // Simulating the current Player 2 (Computer) move
  16. if(Player == 2){
  17. Jogadas *BestValue;
  18. BestValue->pontuacao = -9999;
  19. Lista_ia *MovesP2;
  20. verificar_jogadas_possiveis(tabuleiro, MovesP2, Player);
  21. Jogadas *tmp = (Jogadas*)malloc(sizeof(Jogadas));
  22. for(MovesP2->head = tmp; tmp != NULL; tmp = tmp->prox){
  23. BestMove = minimax(copia, depth - 1, 1);
  24. if(BestMove->pontuacao > BestValue->pontuacao){
  25. BestValue = BestMove;
  26. }
  27. }
  28. return BestMove;
  29. }
  30. // Simulating the best Player 1 move
  31. else{
  32. Jogadas *BestValue;
  33. BestValue->pontuacao = 9999;
  34. Lista_ia *MovesP1;
  35. verificar_jogadas_possiveis(tabuleiro, MovesP1, Player);
  36. Jogadas *aux = (Jogadas*)malloc(sizeof(Jogadas));
  37. for(MovesP1->head = aux; aux != NULL; aux = aux->prox){
  38. BestMove = minimax(copia, depth - 1, 2);
  39. if(BestMove->pontuacao < BestValue->pontuacao){
  40. BestValue = BestMove;
  41. }
  42. }
  43. return BestMove;
  44. }
  45. }
Add Comment
Please, Sign In to add comment