/* This file is a part of othello-ai-guile-c
*
* Copyright (C) 2021 Robby Zambito
*
* othello-ai-guile-c is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* othello-ai-guile-c is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include "othello.h"
int main(int argc, char **argv) {
int exit_status = EXIT_SUCCESS;
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 two 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;
}
errno = 0;
switch (c) {
case 'h':
printf("%s", usage);
exit(EXIT_SUCCESS);
case '1':
player_one_strategy_path = strdup(optarg);
if (access(player_one_strategy_path, F_OK) == -1) {
fprintf(stderr, "Could not access player 1 strategy\n");
exit_status = EXIT_FAILURE;
}
break;
case '2':
player_two_strategy_path = strdup(optarg);
if (access(player_two_strategy_path, F_OK) == -1) {
fprintf(stderr, "Could not access player 2 strategy\n");
exit_status = EXIT_FAILURE;
}
break;
}
}
// Couldn't open one or more of the player strategies, bail out.
if (exit_status == EXIT_FAILURE) {
exit(EXIT_FAILURE);
}
enum player_color winner =
game_loop(player_one_strategy_path, player_two_strategy_path);
free(player_one_strategy_path);
free(player_two_strategy_path);
switch (winner) {
case WHITE:
puts("Congratulations for winning player 1!");
break;
case BLACK:
puts("Congratulations for winning player 2!");
break;
default:
puts("The game ended with no winner.");
}
puts("Here was the final board:");
print_board(get_board());
return EXIT_SUCCESS;
}