From e66c54235e2d38ebc912aca0a74d287374914517 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Wed, 29 Dec 2021 22:53:08 -0500 Subject: Started parsing arguments We will use this to load the strategy file for an AI player. --- cmd/main.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/cmd/main.c b/cmd/main.c index e751856..41aecde 100644 --- a/cmd/main.c +++ b/cmd/main.c @@ -18,16 +18,51 @@ #define _GNU_SOURCE +#include #include #include #include #include +#include #include "othello.h" int main(int argc, char **argv) { - (void)argc; - (void)argv; + static const struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"player-one", required_argument, NULL, '1'}, + {"player-two", required_argument, NULL, '2'}, + {0, 0, 0, 0}}; + + const char *usage = + " -h --help show help output\n" + " -1 --player-one specify a file to use for player one strategy\n" + " -2 --player-two specify a file to use for player one strategy\n"; + + char *player_one_strategy_path = NULL; + char *player_two_strategy_path = NULL; + + int c; + while (1) { + int option_index = 0; + c = getopt_long(argc, argv, "h1:2:", long_options, &option_index); + if (c == -1) { + break; + } + switch (c) { + case 'h': + printf("%s", usage); + exit(EXIT_SUCCESS); + case '1': + free(player_one_strategy_path); + player_one_strategy_path = strdup(optarg); + break; + case '2': + free(player_two_strategy_path); + player_two_strategy_path = strdup(optarg); + break; + } + } enum player_color winner = game_loop(); -- cgit v1.2.3