Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Moteur de tournoi : joueur ***************/
- #include <stdio.h>
- #include <stdlib.h>
- #include "avalam.h"
- #include "moteur.h"
- void choisirCoup(T_Position currentPosition, T_ListeCoups listeCoups) {
- // Cette fonction peut appeler la fonction ecrireIndexCoup(coupChoisi);
- // Pour sélectionner l'index d'un coup à jouer dans la liste l
- // aléatoire
- // ecrireIndexCoup(rand()%listeCoups.nb);
- int i;
- octet o, d;
- int a;
- octet myColor = currentPosition.trait;
- // afficherListeCoups(listeCoups);
- printf("Ma couleur : %s\n", COLNAME(currentPosition.trait));
- if (COLNAME(currentPosition.trait) == 'rouge')
- {
- for (int j = 0; j < listeCoups.nb; ++j)
- {
- o = listeCoups.coups[j].origine;
- d = listeCoups.coups[j].destination;
- printf("Coup %d : ", j);
- printf("%d (%d - %s) ->", o, currentPosition.cols[o].nb, COLNAME(currentPosition.cols[o].couleur));
- printf("%d (%d - %s) \n", d, currentPosition.cols[d].nb, COLNAME(currentPosition.cols[d].couleur));
- if (o == 18
- && d == 19
- && currentPosition.cols[d].couleur != myColor
- ) // le tricks en 18
- {
- ecrireIndexCoup(j);
- return;
- }else if (o == 29
- && d == 28
- && currentPosition.cols[d].couleur != myColor
- ) // le tricks en 28
- {
- ecrireIndexCoup(j);
- return;
- }else if ( (currentPosition.cols[o].couleur != myColor) // Si je peux gagner une colonne, je la prends
- && (currentPosition.cols[d].couleur != myColor)
- && (currentPosition.cols[d].nb != 4)
- ) {
- printf("On choisit ce coup ! \n");
- ecrireIndexCoup(j);
- return; // on quitte la fonction
- }else if ( (currentPosition.cols[o].couleur != myColor) // Sinon, j'empile des pions adverses sauf s'ils conduisent à des tas de 5
- && (currentPosition.cols[d].couleur != myColor)
- && (currentPosition.cols[d].nb != 4)
- ) {
- printf("On choisit ce coup ! \n");
- ecrireIndexCoup(i);
- return; // on quitte la fonction
- }else{
- while (1) {
- a = rand()%listeCoups.nb;
- o = listeCoups.coups[a].origine;
- d = listeCoups.coups[a].destination;
- if ( (currentPosition.cols[o].couleur != myColor)
- && (currentPosition.cols[d].nb != 4) ) {
- printf("On choisit ce coup ! \n");
- ecrireIndexCoup(a);
- return; // on quitte la fonction
- }
- }
- }
- }
- }else{
- /*JE SUIS JAUNE*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement