From 81c34439a34ca6cea0b4c0b3953a79f3acd78f4f Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Fri, 10 Sep 2021 18:23:46 +0200 Subject: [PATCH] First commit --- Makefile | 0 src/Makefile | 26 +++++++++++++++++ src/utictactoe.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ src/utictactoe.h | 0 4 files changed, 101 insertions(+) create mode 100644 Makefile create mode 100644 src/Makefile create mode 100644 src/utictactoe.c create mode 100644 src/utictactoe.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..e58a3d7 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,26 @@ +# Flags +## Build Ultimate TicTacToe +## ------------------------ +## This Makefile Help you to build utictactoe +## -- + + +CC=gcc +CFLAGS=-Wall -g -std=c99 +CPPFLAGS= + +all: utictactoe + +utictactoe: utictactoe.c ## Compile utictactoe.c + $(CC) $(CFQLGS) $< -o $@ + +# Nettoyage +.PHONY: clean help +clean: ## Clean files + rm -f *.o utictactoe + +help: + @echo "Makefile pour UTicTacToe" + @echo "--" + @echo " all: tout compiler" + @echo "clean: nettoyer" diff --git a/src/utictactoe.c b/src/utictactoe.c new file mode 100644 index 0000000..9591c07 --- /dev/null +++ b/src/utictactoe.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include + +void help(){ + printf("usage: utictactoe ([-i LEVEL|-x N|-o N|-v|-V|-h] | -c FILE)\n"); + printf("Play a utictactoe game with human or program players.\n"); + printf("-i, --inception-level LEVEL deepness of the game (min=1, max=3 (default=2))\n"); + printf("-x, --cross-ai N set tactic of cross player 'X'\n"); + printf("-o, --round-ai N set tactic of round player 'O'\n"); + printf("-c, --contest enable 'contest' mode\n"); + printf("-v, --verbose verbose output\n"); + printf("-V, --version display version and exit\n"); + printf("-h, --help display this help and exit\n"); + printf("Tactics list: random (0), clever (1)\n"); +} +int main(int argc, char* argv[]) { + int optc; + int inception_level = 0; + bool contest, round_ai, cross_ai = false; + + char * end_ptr; + static struct option long_opts[] = + { + {"inception-level", optional_argument, 0, 'i'}, + {"cross-ai", no_argument, 0, 'x'}, + {"round-ai", no_argument, 0, 'o'}, + {"contest", no_argument, 0, 'c'}, + {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + while ((optc = getopt_long (argc, argv, "i:xocvVh", long_opts, NULL)) != -1){ + switch (optc) { + case 'i': /* 'a' option */ + printf ("Inception activated\n"); + if ( optarg ) { + inception_level = strtol(optarg, &end_ptr, 10); + assert ( strcmp(end_ptr,"\0") == 0); + assert ( inception_level >= 1 ); + assert ( inception_level <= 3 ); + } + else { + inception_level = 2; + } + break; + case 'x': /* 'a' option */ + printf ("contest activated\n"); + cross_ai = true; + break; + + case 'o': /* 'a' option */ + printf ("contest activated\n"); + round_ai = true; + break; + + case 'c': /* 'a' option */ + printf ("contest activated\n"); + contest = true; + break; + + case 'h': + help(); + exit(EXIT_SUCCESS); + + default: + exit (EXIT_FAILURE); + } + } + printf("Hello World!\n"); +} diff --git a/src/utictactoe.h b/src/utictactoe.h new file mode 100644 index 0000000..e69de29