You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 lines
1.7 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "api.h"
struct stockage {
char *name;
unsigned int nb_joueur;
enum hole_t color;
};
struct stockage storage(unsigned int write, char* name, unsigned int nb_joueur, enum hole_t color) {
static struct stockage stock={NULL,0};
if(write & 1)
stock.color = color;
if(write & 2)
stock.nb_joueur = nb_joueur;
if(write & 4) {
if(stock.name)
free(stock.name);
stock.name = (char*) malloc((strlen(name)+1)*sizeof(char));
if(stock.name)
strncpy(stock.name, name, strlen(name));
}
return stock;
}
void InitLibrary(char name[50]) {
struct stockage stock;
stock = storage(4,name,0,0);
printf("stratégie init %s\n", stock.name);
}
void StartGame() {
puts("stratégie start game");
}
void StartMatch(const unsigned int nb_joueur, const enum hole_t color) {
srand(time(NULL));
struct stockage stock;
stock = storage(3,NULL,nb_joueur, color);
printf("stratégie start match (%d players, color%d)\n", stock.nb_joueur, stock.color);
}
void EndMatch() {
puts("stratégie end match");
}
void EndGame() {
puts("stratégie end game");
}
int NextMove(const SGameState * const gameState, int firstMove, SMove *move) {
struct stockage stock;
size_t i;
int start, end, next;
stock = storage(0, NULL, 0, 0);
printf("joueur %d, pions : [ ", stock.color);
for(i=0;i<121;i++) {
if(gameState->board[i] == stock.color)
printf("%d, ", i);
}
puts(" ]");
if(firstMove)
puts("== premier mouvement ==");
printf("mouvement (start, end, next) ?");
scanf("%d %d %d", &start, &end, &next);
move->startPos = start;
move->endPos = end;
printf("mouvement %d %d %d\n", move->startPos, move->endPos, next);
return next;
}