-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_solve.c
43 lines (40 loc) · 959 Bytes
/
game_solve.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "game.h"
#include "game_aux.h"
#include "game_ext.h"
#include "game_private.h"
#include "game_test.h"
#include "game_tools.h"
int main(int argc, char* argv[])
{
if (argc < 3) {
printf("too little arguments !\n");
return EXIT_FAILURE;
}
char* filename = NULL;
if (argc == 3) {
filename = "default.txt";
} else if (argc >= 4) {
filename = argv[3];
}
game user_game = game_load(argv[2]);
if (strcmp("-s", argv[1]) == 0) {
if (game_solve(user_game)) {
game_save(user_game, filename);
} else {
game_delete(user_game);
return EXIT_FAILURE;
}
} else if (strcmp("-c", argv[1]) == 0) {
FILE* file = fopen(filename, "w");
uint nb_solutions = game_nb_solutions(user_game);
fprintf(file, "%u\n", nb_solutions);
fclose(file);
}
game_delete(user_game);
return EXIT_SUCCESS;
}