First commit
This commit is contained in:
commit
81c34439a3
4 changed files with 101 additions and 0 deletions
0
Makefile
Normal file
0
Makefile
Normal file
26
src/Makefile
Normal file
26
src/Makefile
Normal file
|
@ -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"
|
75
src/utictactoe.c
Normal file
75
src/utictactoe.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
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");
|
||||
}
|
0
src/utictactoe.h
Normal file
0
src/utictactoe.h
Normal file
Loading…
Add table
Add a link
Reference in a new issue