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.
 
 
 
 

170 lines
3.8 KiB

#include "ai.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "gamestate.h"
#include "strategy.h"
#include "list.h"
#include <limits.h>
void casesJoueur (SGameState g, EPlayer p, int * tab)
{
int i=0,j=0;
for(i=0; i<121; i++)
{
if( g.board[i] == p )
{
tab[j] = i; //tab[j] recupere lindice i de la case qui contient le pion du joueur p
j++;
}
}
}
SGameState * initGameState ( int n )
{
int i = 0;
SGameState * gameState = ( SGameState * ) malloc ( sizeof( SGameState ) );
for (i = 0; i < 121; i++)
{
gameState->board[i] = 0;
}
for (i = 0; i < 121; i++)
{
if( i < 10 )
gameState->board[i] = 1;
else if( (10 <= i && i <= 13) || (23 <= i && i <= 25) || (35 <= i && i <= 36) || (i == 46) )
gameState->board[i] = 2;
else if( (19 <= i && i <= 22) || (32 <= i && i <= 34) || (44 <= i && i <= 45) || (i == 55) )
gameState->board[i] = 3;
else if( (98 <= i && i <= 101) || (86 <= i && i <= 88) || (75 <= i && i <= 76) || (i == 65) )
gameState->board[i] = 4;
else if( (107 <= i && i <= 110) || (95 <= i && i <= 97) || (84 <= i && i <= 85) || (i == 74) )
gameState->board[i] = 5;
else if( 111 <= i )
gameState->board[i] = 6;
}
return( gameState );
}
void afficherGameState (SGameState gameState)
{
int i, j, offset = 12, dir = 1, pawn = 0;
for(i = 0; i < 17; i++) { /* 17 lignes */
if(i%4 == 0) /* inversion de la pente toutes les 4 lignes */
dir = -dir;
if(i == 4) /* base du 2nd triangle */
offset = 0;
else if(i == 13) /* base du 1er triangle */
offset = 9;
putchar('\t');
for(j = 0; j < 13; j++) { /* 13 colonnes */
if(j < offset)
putchar(' ');
else
printf("%1d ", gameState.board[pawn++]);
}
putchar('\n');
offset += dir; /* continuer sur la pente */
}
putchar('\n');
}
void afficherDestination (const SGameState* const state)
{
int i, j, offset = 12, dir = 1, pawn = 0;
for(i = 0; i < 17; i++) { /* 17 lignes */
if(i%4 == 0) /* inversion de la pente toutes les 4 lignes */
dir = -dir;
if(i == 4) /* base du 2nd triangle */
offset = 0;
else if(i == 13) /* base du 1er triangle */
offset = 9;
putchar('\t');
for(j = 0; j < 13; j++) { /* 13 colonnes */
if(j < offset)
putchar(' ');
else
printf("%1d ", nearestEmptyDestinationHole(pawn++, state));
}
putchar('\n');
offset += dir; /* continuer sur la pente */
}
putchar('\n');
}
int main()
{
char name[50];
InitLibrary(name);
SGameState state;
bzero(state.board, 121*sizeof(int));
for (int i=0; i<9; i++)
state.board[i] = color4;
state.board[15] = color4;
StartMatch(6, color4);
StartGame();
afficherDestination(&state);
afficherGameState(state);
SMove m;
while (1)
{
int firstMove = 1;
while (NextMove(&state, firstMove, &m))
{
state.board[m.endPos] = state.board[m.startPos];
state.board[m.startPos] = none;
printf("Test : %d\t%d\n", m.startPos, m.endPos);
afficherGameState(state);
firstMove = 0;
if (distance(m.startPos, m.endPos) == 1)
break;
}
printf("\n\nNextMove\n\n");
getchar();
}
//printf("%lu\n", (long unsigned int)sizeof(LCell));
EndGame();
EndMatch();
return 0;
}
/*
#include "queue.h"
int main()
{
Queue* q = NULL;
push(&q, (Tree*) 1);
debugQueue(q);
printf("%p\n", pop(&q));
debugQueue(q);
return 0;
}
*/