-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
52 lines (42 loc) · 909 Bytes
/
main.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
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include "game.h"
#include "parser.h"
#include "solver.h"
#include "SPBufferset.h"
#include "main_aux.h"
#define MAX_COMMAND_SIZE 1026
int main(int argc, char *argv[]){
Command* command;
Board* board;
char userInput[MAX_COMMAND_SIZE] = { 0 };
if(argc > 1)
srand(atoi(argv[1]));
SP_BUFF_SET();
board = create_blank_board(9,3,3);
generate_user_board(board);
printBoard(board,0);
while(1){
if (fgets(userInput, MAX_COMMAND_SIZE, stdin) == NULL) {
if (ferror(stdin)) {
printf("Error: fgets has failed\n");
}
destroyBoard(board);
printf("Exiting...\n");
return 0;
}
command = parse_command(userInput);
if (!command) {
/*
* Could not parse a legal command, skipping.
*/
continue;
}
execute_command(command, board);
}
destroyBoard(board);
return 0;
}