Advertisement
Guest User

Untitled

a guest
May 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.34 KB | None | 0 0
  1. /********* Moteur de tournoi : joueur ***************/
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "avalam.h"
  6. #include "moteur.h"
  7.  
  8.  
  9. void choisirCoup(T_Position currentPosition, T_ListeCoups listeCoups) {
  10.     // Cette fonction peut appeler la fonction ecrireIndexCoup(coupChoisi);
  11.     // Pour sélectionner l'index d'un coup à jouer dans la liste l
  12.  
  13.     // aléatoire
  14.     // ecrireIndexCoup(rand()%listeCoups.nb);
  15.  
  16.     int i;
  17.     octet o, d;
  18.     int a;
  19.     octet myColor = currentPosition.trait;
  20.  
  21.     // afficherListeCoups(listeCoups);
  22.  
  23.     printf("Ma couleur : %s\n", COLNAME(currentPosition.trait));
  24.  
  25.     if (COLNAME(currentPosition.trait) == 'rouge')
  26.     {
  27.         for (int j = 0; j < listeCoups.nb; ++j)
  28.         {
  29.             o = listeCoups.coups[j].origine;
  30.             d = listeCoups.coups[j].destination;  
  31.  
  32.         printf("Coup %d : ", j);
  33.         printf("%d (%d - %s) ->", o, currentPosition.cols[o].nb, COLNAME(currentPosition.cols[o].couleur));
  34.         printf("%d (%d - %s) \n", d, currentPosition.cols[d].nb, COLNAME(currentPosition.cols[d].couleur));
  35.         if (o == 18
  36.             && d == 19
  37.             && currentPosition.cols[d].couleur != myColor
  38.             )                                                       // le tricks en 18
  39.         {
  40.             ecrireIndexCoup(j);
  41.             return;
  42.         }else if (o == 29
  43.                   && d == 28
  44.                   && currentPosition.cols[d].couleur != myColor
  45.                   )                                                     // le tricks en 28
  46.         {
  47.             ecrireIndexCoup(j);
  48.             return;
  49.         }else if ( (currentPosition.cols[o].couleur != myColor) // Si je peux gagner une colonne, je la prends
  50.         && (currentPosition.cols[d].couleur != myColor)
  51.         && (currentPosition.cols[d].nb != 4)
  52.         ) {
  53.             printf("On choisit ce coup ! \n");
  54.             ecrireIndexCoup(j);
  55.             return; // on quitte la fonction
  56.         }else if ( (currentPosition.cols[o].couleur != myColor) // Sinon, j'empile des pions adverses sauf s'ils conduisent à des tas de 5
  57.         && (currentPosition.cols[d].couleur != myColor)
  58.         && (currentPosition.cols[d].nb != 4)
  59.         ) {
  60.             printf("On choisit ce coup ! \n");
  61.             ecrireIndexCoup(i);
  62.             return; // on quitte la fonction
  63.         }else{
  64.             while (1) {
  65.         a = rand()%listeCoups.nb;
  66.         o = listeCoups.coups[a].origine;
  67.         d = listeCoups.coups[a].destination;  
  68.  
  69.         if ( (currentPosition.cols[o].couleur != myColor)
  70.         && (currentPosition.cols[d].nb != 4) ) {
  71.             printf("On choisit ce coup ! \n");
  72.             ecrireIndexCoup(a);
  73.             return; // on quitte la fonction
  74.         }
  75.     }
  76.         }
  77.         }
  78.     }else{
  79.         /*JE SUIS JAUNE*/
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement