summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2021-12-29 22:53:08 -0500
committerRobby Zambito <contact@robbyzambito.me>2021-12-29 22:53:08 -0500
commite66c54235e2d38ebc912aca0a74d287374914517 (patch)
tree1c5f231d174fa00ec1fad7f5fb44e8fc96039d6b
parentb9113f203b831e8d4f7cfeeff4701b07da0ea44e (diff)
Started parsing arguments
We will use this to load the strategy file for an AI player.
-rw-r--r--cmd/main.c39
1 files 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 <getopt.h>
#include <libguile.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#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 <file> specify a file to use for player one strategy\n"
+ " -2 --player-two <file> 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();