#include #include void afficher_jeu(char morpion[4][4]) { printf("%c %c %c %c\n", morpion[0][0], morpion[1][0], morpion[2][0], morpion[3][0]); printf("%c %c %c %c\n", morpion[0][1], morpion[1][1], morpion[2][1], morpion[3][1]); printf("%c %c %c %c\n", morpion[0][2], morpion[1][2], morpion[2][2], morpion[3][2]); printf("%c %c %c %c\n\n", morpion[0][3], morpion[1][3], morpion[2][3], morpion[3][3]); } void creer_jeu(char morpion[4][4]) { morpion[0][0] = ' '; morpion[0][1] = '1'; morpion[1][0] = '1'; morpion[0][2] = '2'; morpion[2][0] = '2'; morpion[0][3] = '3'; morpion[3][0] = '3'; int i = 1; int j = 1; for (i = 1; i <= 3; i++) { for (j = 1; j <= 3; j++) { morpion[i][j] = '.'; } } } int tester_vic_j1(char morpion[4][4]) { if ((morpion[1][1] == 'o') && (morpion[1][2] == 'o') && (morpion[1][3] == 'o')) //Première ligne { printf("Joueur 1 gagne !\n\n"); return 1; } else if ((morpion[2][1] == 'o') && (morpion[2][2] == 'o') && (morpion[2][3] == 'o')) //Deuxième ligne { printf("Joueur 1 gagne !\n\n"); return 1; } else if ((morpion[3][1] == 'o') && (morpion[3][2] == 'o') && (morpion[3][3] == 'o')) //Troisième ligne { printf("Joueur 1 gagne !\n\n"); return 1; } else if ((morpion[1][1] == 'o') && (morpion[2][1] == 'o') && (morpion[3][1] == 'o')) //Première colonne { printf("Joueur 1 gagne !\n\n"); return 1; } else if ((morpion[1][2] == 'o') && (morpion[2][2] == 'o') && (morpion[3][2] == 'o')) //Deuxième colonne { printf("Joueur 1 gagne !\n\n"); return 1; } else if ((morpion[1][3] == 'o') && (morpion[2][3] == 'o') && (morpion[3][3] == 'o')) //Troisième colonne { printf("Joueur 1 gagne !\n\n"); return 1; } else if ((morpion[1][1] == 'o') && (morpion[2][2] == 'o') && (morpion[3][3] == 'o')) //Diagonale 11-33 { printf("Joueur 1 gagne !\n\n"); return 1; } else if ((morpion[3][1] == 'o') && (morpion[2][2] == 'o') && (morpion[1][3] == 'o')) //Diagonale 31-13 { printf("Joueur 1 gagne !\n\n"); return 1; } else { return 0; } } int tester_vic_j2(char morpion[4][4]) { if ((morpion[1][1] == 'x') && (morpion[1][2] == 'x') && (morpion[1][3] == 'x')) //Première ligne { printf("Joueur 2 gagne !\n\n"); return 1; } else if ((morpion[2][1] == 'x') && (morpion[2][2] == 'x') && (morpion[2][3] == 'x')) //Deuxième ligne { printf("Joueur 2 gagne !\n\n"); return 1; } else if ((morpion[3][1] == 'x') && (morpion[3][2] == 'x') && (morpion[3][3] == 'x')) //Troisième ligne { printf("Joueur 2 gagne !\n\n"); return 1; } else if ((morpion[1][1] == 'x') && (morpion[2][1] == 'x') && (morpion[3][1] == 'x')) //Première colonne { printf("Joueur 2 gagne !\n\n"); return 1; } else if ((morpion[1][2] == 'x') && (morpion[2][2] == 'x') && (morpion[3][2] == 'x')) //Deuxième colonne { printf("Joueur 2 gagne !\n\n"); return 1; } else if ((morpion[1][3] == 'x') && (morpion[2][3] == 'x') && (morpion[3][3] == 'x')) //Troisième colonne { printf("Joueur 2 gagne !\n\n"); return 1; } else if ((morpion[1][1] == 'x') && (morpion[2][2] == 'x') && (morpion[3][3] == 'x')) //Diagonale 11-33 { printf("Joueur 2 gagne !\n\n"); return 1; } else if ((morpion[3][1] == 'x') && (morpion[2][2] == 'x') && (morpion[1][3] == 'x')) //Diagonale 31-13 { printf("Joueur 2 gagne !\n\n"); return 1; } else { return 0; } } void jouer_j1(char morpion[4][4]) { int choix_case = 0; int choix_ok = 0; while (choix_ok != 1) { printf("J1 vous jouez les o\n"); printf("Quelle case ?\n"); scanf("%d", &choix_case); if (choix_case != (11 || 12 || 13 || 21 || 22 || 23 || 31 || 32 || 33)) { printf("Ceci n'est pas une case, sorry\n"); } else { int line = choix_case/10; int column = choix_case%10; if (morpion[line][column] != '.') { printf("Cette case est deja occupee, sorry\n"); } else { morpion[line][column] = 'o'; choix_ok = 1; } } } void jouer_j2(char morpion[4][4]) { int choix_case_j2 = 0; int choix_ok = 0; while (choix_ok != 1) { printf("J2 vous jouez les x\n"); printf("Quelle case ?\n"); scanf("%d", &choix_case_j2); if (choix_case != (11 || 12 || 13 || 21 || 22 || 23 || 31 || 32 || 33)) { printf("Ceci n'est pas une case, sorry\n"); } else { int line = choix_case_j2/10; int column = choix_case_j2%10; if (morpion[line][column] != '.') { printf("Cette case est deja occupee, sorry\n"); } else { morpion[line][column] = 'x'; choix_ok = 1; } } } void jeu(void) { char morpion[4][4]; int victoire = 0; creer_jeu(morpion); jouer_j1(morpion); afficher_jeu(morpion); victoire = tester_vic_j1(morpion); jouer_j2(morpion); afficher_jeu(morpion); victoire = tester_vic_j2(morpion); } int main(void) { jeu(); return EXIT_SUCCESS; }