-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsnake.c
54 lines (44 loc) · 1.25 KB
/
snake.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
52
53
54
#include <stdio.h>
#include <string.h>
#include "snake_utils.h"
#include "state.h"
int main(int argc, char* argv[]) {
char* in_filename = NULL;
char* out_filename = NULL;
game_state_t* state = NULL;
// Parse arguments
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-i") == 0 && i < argc - 1) {
in_filename = argv[i + 1];
i++;
continue;
}
if (strcmp(argv[i], "-o") == 0 && i < argc - 1) {
out_filename = argv[i + 1];
i++;
continue;
}
fprintf(stderr, "Usage: %s [-i filename] [-o filename]\n", argv[0]);
return 1;
}
// Do not modify anything above this line.
/* Task 7 */
// Read board from file, or create default board
if (in_filename != NULL) {
// TODO: Load the board from in_filename
// TODO: If the file doesn't exist, return -1
// TODO: Then call initialize_snakes on the state you made
} else {
// TODO: Create default state
}
// TODO: Update state. Use the deterministic_food function
// (already implemented in snake_utils.h) to add food.
// Write updated board to file or stdout
if (out_filename != NULL) {
// TODO: Save the board to out_filename
} else {
// TODO: Print the board to stdout
}
// TODO: Free the state
return 0;
}