#include
#include
#include “snake_utils.h”
#include “state.h”
int main(int argc, char* argv[]) {
bool io_stdin = false;
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) {
if (io_stdin) {
fprintf(stderr, "Usage: %s [-i filename | --stdin] [-o filename]\n", argv[0]);
in_filename = argv[i + 1];
} else if (strcmp(argv[i], "--stdin") == 0) {
if (in_filename != NULL) {
fprintf(stderr, "Usage: %s [-i filename | --stdin] [-o filename]\n", argv[0]);
io_stdin = true;
if (strcmp(argv[i], "-o") == 0 && i < argc - 1) {
out_filename = argv[i + 1];
fprintf(stderr, "Usage: %s [-i filename | --stdin] [-o filename]\n", argv[0]);
// 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 if (io_stdin) {
// TODO: Load the board from stdin
// TODO: Then call initialize_snakes on the state you made
// 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
// TODO: Print the board to stdout
// TODO: Free the state