int main() { morpion_t partie = creer_partie(); int vainqueur = VIDE , i = 0; while(vainqueur == VIDE && i < 9) { vainqueur = tour(&partie); afficher_plateau(partie); changer_joueur(&partie); i++; } if(vainqueur == ROND) printf("LE JOUEUR ROND A GAGNÉ\n"); else if(vainqueur == CROIX) printf("LE JOUEUR CROIX A GAGNÉ\n"); else printf("PERSONNE N'A GAGNE\n"); return EXIT_SUCCESS; }
/** @ingroup test * @brief Teste le bon fonctionnement de partie_jouer_coup(). * */ void test_coup(void) { Partie partie = creer_partie(); partie->plateau = creer_plateau(9); partie->initialisee = true; partie->finie = false; // à tester sur valgrind partie->joueur_courant = JOUEUR_NOIR; s_Coup coup = {position(1, 0, 9)}; (void) coup; assert(partie_jouer_coup(partie, coup)); coup.position = POSITION_INVALIDE; assert(partie_jouer_coup(partie, coup)); coup.position = position(0, 1, 9); assert(partie_jouer_coup(partie, coup)); coup.position = position(0, 0, 9); assert(partie_jouer_coup(partie, coup) == false); detruire_partie(partie); }
struct { const char* name; bool(*fonct)(Partie, FILE*, const char*); } handlers[] = { {.name = "passer", .fonct = handle_passer}, {.name = "afficher", .fonct = handle_afficher}, {.name = "charger", .fonct = handle_charger}, {.name = "#", .fonct = handle_commentaire}, {.name = "!", .fonct = handle_message}, {.name = "fail", .fonct = handle_fail}, {.name = "vide", .fonct = handle_vide}, {.name = "annuler", .fonct = handle_annuler}, {.name = "rejouer", .fonct = handle_rejouer}, {.name = "assert_partie_finie", .fonct = handle_assert_partie_finie}, }; Partie partie = creer_partie(); initialisation_partie(partie, test_reponses_aux_questions, NULL); bool reussi; FILE* file = fopen(filename, "r"); if (file == NULL) { printf("impossible d'ouvrir %s\n", filename); reussi = false; goto out; } char buf[256]; while (fgets(buf, sizeof(buf), file)) { buf[strlen(buf) - 1] = 0; if (buf[0] == 0) // ligne vide