IA presque fonctionnelle
This commit is contained in:
parent
852ed855fc
commit
14850bd05f
278
src/IAEngine.c
278
src/IAEngine.c
@ -1,3 +1,12 @@
|
||||
/*
|
||||
* IAEngine.c
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*
|
||||
* Fonction qui va définir le comportement joueur(s) "ordinateur"
|
||||
*/
|
||||
|
||||
#include "playerInterface.h"
|
||||
#include "arenaEngine.h"
|
||||
#include "IAEngine.h"
|
||||
@ -36,9 +45,14 @@ int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
||||
|
||||
int action;
|
||||
|
||||
if(((player2->PositionX == player1->PositionX ) && (player2->PositionY +1 == player1->PositionY ))||((player2->PositionX == player1->PositionX ) && (player2->PositionY -1 == player1->PositionY ))||((player2->PositionX + 1 == player1->PositionX ) && (player2->PositionY == player1->PositionY ))||((player2->PositionX - 1 == player1->PositionX ) && (player2->PositionY == player1->PositionY )))
|
||||
{
|
||||
action=5;
|
||||
}
|
||||
|
||||
//action = FindShortestPath(player1->PositionX,player1->PositionY,player2->PositionX,player2->PositionY);
|
||||
action = FindPath(arena,player1,player2);
|
||||
printf("ACTION = %i",action);
|
||||
printf("Tour de l'IA\n");
|
||||
if(action == 5)
|
||||
{
|
||||
@ -62,7 +76,6 @@ int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
||||
|
||||
int FindPath(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
||||
{
|
||||
|
||||
int action;
|
||||
|
||||
int compteur = 0;
|
||||
@ -77,76 +90,105 @@ int FindPath(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
||||
NOEUD * n1 =NULL;
|
||||
n1=(NOEUD*)malloc(sizeof(NOEUD));
|
||||
|
||||
posX = player2->PositionX -1;
|
||||
posY = player2->PositionY ;
|
||||
//posX = player2->PositionX -1;
|
||||
//posY = player2->PositionY ;
|
||||
|
||||
n1->actualX = player2->PositionX -1;
|
||||
n1->actualY = player2->PositionY;
|
||||
|
||||
n1->min=3000;
|
||||
n1->compteur=0;
|
||||
|
||||
n1->ParentX = player2->PositionX;
|
||||
n1->ParentY = player2->PositionY;
|
||||
|
||||
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||
if(((n1->actualX >= 0) && (n1->actualX < NB_BLOCS_LARGEUR ))&& ((n1->actualY >= 0) && (n1->actualY < NB_BLOCS_HAUTEUR)) && (abs(player1->PositionX - n1->actualX) >= abs(player1->PositionY - n1->actualY)))
|
||||
{
|
||||
if(getTileTypeID(arena,posX,posY) == 0)
|
||||
if((player2->PositionX -1 == player1->PositionX ) && (player2->PositionY == player1->PositionY ))
|
||||
{
|
||||
return action=5;
|
||||
}
|
||||
else if(getTileTypeID(arena,n1->actualX,n1->actualY) == 0)
|
||||
{
|
||||
n1->compteur = n1->compteur+1;
|
||||
//direction = GAUCHE;
|
||||
n1=CalculatePath(arena,posX,posY,n1,player1,player2,compteur,0,minG);
|
||||
n1=CalculatePath(arena,n1,player1,player2,compteur,0,minG);
|
||||
minG=n1->min;
|
||||
printf("minG = %i\n",minG);
|
||||
printf(" FINAL minG = %i\n",minG);
|
||||
}
|
||||
printf("AAAAAAAA\n");
|
||||
}
|
||||
|
||||
|
||||
else if(n1->compteur != (abs(player1->PositionX - player2->PositionX) + abs(player1->PositionY - player2->PositionY)))
|
||||
{
|
||||
|
||||
|
||||
//1 vers le haut
|
||||
posX = player2->PositionX;
|
||||
posY = player2->PositionY - 1;
|
||||
n1->actualX = player2->PositionX;
|
||||
n1->actualY = player2->PositionY - 1;
|
||||
|
||||
if(((posX >=0) && (posX <NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||
if(((n1->actualX >=0) && (n1->actualX <NB_BLOCS_LARGEUR ))&& ((n1->actualY >= 0) && (n1->actualY < NB_BLOCS_HAUTEUR))&& (abs(player1->PositionX - n1->actualX) <= abs(player1->PositionY - n1->actualY)))
|
||||
{
|
||||
|
||||
if(getTileTypeID(arena,posX,posY) == 0)
|
||||
if((player2->PositionX +1 == player1->PositionX ) && (player2->PositionY == player1->PositionY ))
|
||||
{
|
||||
return action=5;
|
||||
}
|
||||
else if(getTileTypeID(arena,n1->actualX,n1->actualY) == 0)
|
||||
{
|
||||
//direction = HAUT;
|
||||
|
||||
n1=CalculatePath(arena,posX,posY,n1,player1,player2,compteur,0,minH);
|
||||
n1->compteur = n1->compteur + 1;
|
||||
n1=CalculatePath(arena,n1,player1,player2,compteur,0,minH);
|
||||
minH=n1->min;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if(n1->compteur != (abs(player1->PositionX - player2->PositionX) + abs(player1->PositionY - player2->PositionY)))
|
||||
{
|
||||
//1 vers le bas
|
||||
posX = player2->PositionX;
|
||||
posY = player2->PositionY + 1;
|
||||
n1->actualX = player2->PositionX;
|
||||
n1->actualY = player2->PositionY + 1;
|
||||
|
||||
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY >=0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||
if(((n1->actualX >= 0) && (n1->actualX < NB_BLOCS_LARGEUR ))&& ((n1->actualY >=0) && (n1->actualY < NB_BLOCS_HAUTEUR))&& (abs(player1->PositionX - n1->actualX) >= abs(player1->PositionY - n1->actualY)))
|
||||
{
|
||||
if(getTileTypeID(arena,posX,posY) == 0)
|
||||
if((player2->PositionX == player1->PositionX ) && (player2->PositionY +1 == player1->PositionY ))
|
||||
{
|
||||
return action=5;
|
||||
}
|
||||
else if(getTileTypeID(arena,n1->actualX,n1->actualY) == 0)
|
||||
{
|
||||
n1->compteur = n1->compteur + 1;
|
||||
//direction = BAS;
|
||||
n1=CalculatePath(arena,posX,posY,n1,player1,player2,compteur,0,minB);
|
||||
n1=CalculatePath(arena,n1,player1,player2,compteur,0,minB);
|
||||
minB=n1->min;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(n1->compteur != (abs(player1->PositionX - player2->PositionX) + abs(player1->PositionY - player2->PositionY)))
|
||||
{
|
||||
|
||||
//1 vers la droite
|
||||
posX = player2->PositionX +1;
|
||||
posY = player2->PositionY ;
|
||||
n1->actualX = player2->PositionX +1;
|
||||
n1->actualY = player2->PositionY ;
|
||||
|
||||
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||
if(((n1->actualX >= 0) && (n1->actualX < NB_BLOCS_LARGEUR ))&& ((n1->actualY >= 0) && (n1->actualY < NB_BLOCS_HAUTEUR))&& (abs(player1->PositionX - n1->actualX) <= abs(player1->PositionY - n1->actualY)))
|
||||
{
|
||||
if(getTileTypeID(arena,posX,posY) == 0)
|
||||
if(getTileTypeID(arena,n1->actualX,n1->actualY) == 0)
|
||||
|
||||
{
|
||||
//direction = DROITE;
|
||||
|
||||
n1=CalculatePath(arena,posX,posY,n1,player1,player2,compteur,0,minD);
|
||||
n1->compteur = n1->compteur + 1;
|
||||
n1=CalculatePath(arena,n1,player1,player2,compteur,0,minD);
|
||||
minD=n1->min;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
printf("minG = %i\n",minG);
|
||||
printf("minH = %i\n",minH);
|
||||
printf("minB = %i\n",minB);
|
||||
@ -182,7 +224,9 @@ int FindPath(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if(minD < minH)
|
||||
@ -212,14 +256,18 @@ int FindPath(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
free(n1);
|
||||
return action;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int distance(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
/* distance euclidienne */
|
||||
@ -232,52 +280,50 @@ int distance(int x1, int y1, int x2, int y2)
|
||||
}
|
||||
|
||||
|
||||
NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1,PLAYER * player2, int compteur, int dist,int min)
|
||||
NOEUD * CalculatePath(ARENA_H_TILE* arena,NOEUD * n1,PLAYER * player1,PLAYER * player2, int compteur, int dist,int min)
|
||||
{
|
||||
|
||||
int ID;
|
||||
|
||||
if(((posX - 1 >= 0) && (posX - 1 < NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||
{
|
||||
if((n1->ParentX == player1->PositionX ) && ( n1->ParentY == player1->PositionY))
|
||||
{
|
||||
printf("n1->ParentX - 1 = %i et n1->ParentY =%i\n",n1->ParentX - 1 ,n1->ParentY);
|
||||
printf("RETURN N1\n");
|
||||
return n1;
|
||||
}
|
||||
int differenceX ;
|
||||
int differenceY ;
|
||||
|
||||
ID=getTileTypeID(arena,posX - 1,posY);
|
||||
|
||||
if(( ID== 0) && (posX-1 != n1->ParentX))
|
||||
//Si la position désirée est dans l'arène
|
||||
if(((n1->actualX -1 >= 0) && (n1->actualX -1 < NB_BLOCS_LARGEUR ))&& ((n1->actualY >= 0) && (n1->actualY < NB_BLOCS_HAUTEUR)) && (n1->actualX -1 != n1->ParentX))
|
||||
{
|
||||
ID=getTileTypeID(arena,n1->actualX -1 ,n1->actualY);
|
||||
differenceX = abs(n1->actualX - player1->PositionX);
|
||||
differenceY = abs(n1->actualY - player1->PositionY);
|
||||
|
||||
if(( ID== 0) && (n1->actualX != player1->PositionX) )
|
||||
{
|
||||
n1->ParentX = posX - 1;
|
||||
//Vers la gauche
|
||||
n1->ParentX = n1->actualX;
|
||||
n1->ParentY = n1->actualY;
|
||||
|
||||
n1->actualX = n1->actualX -1;
|
||||
|
||||
n1->compteur = n1->compteur + 1;
|
||||
//compteur = compteur + 1;
|
||||
|
||||
printf("*****111*****\n");
|
||||
|
||||
printf("Position Player1 X: %i et Y: %i\n",player1->PositionX,player1->PositionY);
|
||||
printf("Position n1 player2 X: %i et Y: %i\n",n1->ParentX,n1->ParentY);
|
||||
printf("Position Player2 posX: %i et posY: %i\n",posX,posY);
|
||||
printf("Position Player2 posX: %i et posY: %i\n",n1->actualX,n1->actualY);
|
||||
printf("ID de posx - 1 et posY : %i\n",ID);
|
||||
|
||||
//while((posX - 1 != player1->PositionX) && (posY != player1->PositionY))
|
||||
while((posX - 1 != player1->PositionX) || (posY != player1->PositionY))
|
||||
while(((n1->actualX != player1->PositionX) || (n1->actualY != player1->PositionY)) && (abs(n1->actualX - player1->PositionX) <= differenceX) && (abs(n1->actualY - player1->PositionY) <= differenceY))
|
||||
{
|
||||
|
||||
/*printf("*****222*****\n");
|
||||
printf("Position Player1 X: %i et Y: %i\n",player1->PositionX,player1->PositionY);
|
||||
printf("Position n1 player2 X: %i et Y: %i\n",n1->ParentX,n1->ParentY);
|
||||
printf("Position Player2 posX: %i et posY: %i\n",posX,posY);
|
||||
printf("ID de posx - 1 et posY : %i\n",ID);*/
|
||||
|
||||
n1=CalculatePath(arena,posX - 1,posY,n1,player1,player2,compteur,dist,min);
|
||||
n1=CalculatePath(arena,n1,player1,player2,compteur,dist,min);
|
||||
|
||||
//Post-Traitement
|
||||
//Calcul du "poids" du chemin (nb de coups)
|
||||
|
||||
dist = distance(player1->PositionX,player1->PositionY,posX - 1,posY) + n1->compteur;
|
||||
|
||||
dist = distance(player1->PositionX,player1->PositionY,n1->actualX,n1->actualY) + n1->compteur;
|
||||
|
||||
//printf("DIFFERENCE : %i\n",dist);
|
||||
if(dist < n1->min)
|
||||
{
|
||||
printf("On rentre dans le min\n");
|
||||
@ -286,66 +332,74 @@ NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER
|
||||
return n1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("player2->PositionX : %i \n",player2->PositionX );
|
||||
printf("n1->compteur : %i \n",n1->compteur );
|
||||
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||
if(n1->compteur == abs(player2->PositionX - player1->PositionY)-1)
|
||||
printf("abs(player2->PositionX - player1->PositionY) : %i \n",abs(player2->PositionX - player1->PositionX) );
|
||||
if(n1->compteur == (abs(player2->PositionX - player1->PositionX) + abs(player2->PositionY - player1->PositionY)))
|
||||
{
|
||||
printf("Chemin plus court trouvé\n");
|
||||
n1->min=n1->compteur;
|
||||
//n1->min=n1->compteur;
|
||||
printf("n1->compteur : %i \n",n1->compteur );
|
||||
printf("n1->min : %i \n",n1->min );
|
||||
return n1;
|
||||
}
|
||||
}
|
||||
|
||||
if(((posX +1 >= 0) && (posX + 1 < NB_BLOCS_LARGEUR ))&& ((posY >= 0) && (posY < NB_BLOCS_HAUTEUR)))
|
||||
if(((n1->actualX +1 >= 0) && (n1->actualX + 1 < NB_BLOCS_LARGEUR ))&& ((n1->actualY >= 0) && (n1->actualY < NB_BLOCS_HAUTEUR))&& (n1->actualX +1 != n1->ParentX))
|
||||
{
|
||||
if((n1->ParentX == player1->PositionX ) && ( n1->ParentY == player1->PositionY))
|
||||
if((n1->actualX == player1->PositionX ) && ( n1->actualY == player1->PositionY))
|
||||
{
|
||||
printf("n1->ParentX + 1 = %i et n1->ParentY =%i\n",n1->ParentX + 1 ,n1->ParentY);
|
||||
printf("n1->ActualX = %i et n1->actualY =%i\n",n1->actualX,n1->actualY);
|
||||
printf("RETURN N1\n");
|
||||
return n1;
|
||||
}
|
||||
|
||||
|
||||
if((getTileTypeID(arena,posX + 1 ,posY) == 0) && (posX + 1 != n1->ParentX))
|
||||
if((getTileTypeID(arena,n1->actualX + 1 ,n1->actualY) == 0) && (n1->actualY + 1 != n1->ParentX))
|
||||
{
|
||||
n1->ParentX = posX + 1;
|
||||
n1->ParentX = n1->actualX;
|
||||
n1->ParentY = n1->actualY;
|
||||
n1->actualX = n1->actualX +1;
|
||||
//Vers la droite
|
||||
n1->compteur = n1->compteur + 1;
|
||||
//compteur = compteur + 1;
|
||||
|
||||
//while((posX != player1->PositionX) && (posY != player1->PositionY))
|
||||
while((posX != player1->PositionX) || (posY != player1->PositionY))
|
||||
while(((n1->actualX != player1->PositionX) || (n1->actualY != player1->PositionY)) && (abs(n1->actualX - player1->PositionX) <= differenceX) && (abs(n1->actualY - player1->PositionY) <= differenceY))
|
||||
{
|
||||
|
||||
n1=CalculatePath(arena,posX + 1,posY,n1,player1,player2,compteur,dist,min);
|
||||
n1=CalculatePath(arena,n1,player1,player2,compteur,dist,min);
|
||||
|
||||
//Post-Traitement
|
||||
//Calcul du "poids" du chemin (nb de coups)
|
||||
dist = distance(player1->PositionX,player1->PositionY,posX + 1,posY) + n1->compteur;
|
||||
dist = distance(player1->PositionX,player1->PositionY,n1->actualX,n1->actualY) + n1->compteur;
|
||||
|
||||
printf("DIST = %i\n",dist);
|
||||
if(dist < n1->min)
|
||||
{
|
||||
n1->min=dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("n1->compteur : %i \n",n1->compteur );
|
||||
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||
if(n1->compteur == abs(player2->PositionX - player1->PositionY)-1)
|
||||
{
|
||||
printf("Chemin plus court trouvé\n");
|
||||
n1->min=n1->compteur;
|
||||
return n1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY + 1 >=0) && (posY + 1<NB_BLOCS_HAUTEUR)))
|
||||
printf("n1->compteur : %i \n",n1->compteur );
|
||||
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY) );
|
||||
if(n1->compteur == (abs(player2->PositionX - player1->PositionX)+abs(player2->PositionY - player1->PositionY)))
|
||||
{
|
||||
printf("Chemin plus court trouvé\n");
|
||||
//n1->min=n1->compteur;
|
||||
return n1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if((((n1->actualX >= 0) && (n1->actualX < NB_BLOCS_LARGEUR ))&& ((n1->actualY + 1 >=0) && (n1->actualY + 1<NB_BLOCS_HAUTEUR)))&& (n1->actualY +1 != n1->ParentY))
|
||||
{
|
||||
//VERS LE BAS
|
||||
if((n1->ParentX == player1->PositionX ) && ( n1->ParentY == player1->PositionY))
|
||||
{
|
||||
printf("n1->ParentX = %i et n1->ParentY +1 =%i\n",n1->ParentX ,n1->ParentY+1);
|
||||
@ -353,41 +407,50 @@ NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER
|
||||
return n1;
|
||||
}
|
||||
|
||||
if((getTileTypeID(arena,posX,posY + 1) == 0) && (posY + 1 != n1->ParentY))
|
||||
|
||||
|
||||
if((getTileTypeID(arena,n1->actualX,n1->actualY + 1) == 0) && (n1->actualY + 1!= n1->ParentY) )
|
||||
{
|
||||
n1->ParentY = posY + 1;
|
||||
n1->ParentX = n1->actualX;
|
||||
n1->ParentY = n1->actualY;
|
||||
|
||||
n1->actualY = n1->actualY +1;
|
||||
|
||||
n1->compteur = n1->compteur + 1;
|
||||
|
||||
//Vers la bas
|
||||
n1->compteur = n1->compteur + 1;
|
||||
//compteur = compteur + 1;
|
||||
|
||||
//while((posX != player1->PositionX) && (posY != player1->PositionY))
|
||||
while((posX != player1->PositionX) || (posY != player1->PositionY))
|
||||
while(((n1->actualX != player1->PositionX) || (n1->actualY != player1->PositionY)) && (abs(n1->actualX - player1->PositionX) <= differenceX) && (abs(n1->actualY - player1->PositionY) <= differenceY))
|
||||
{
|
||||
n1=CalculatePath(arena,posX,posY + 1,n1,player1,player2,compteur,dist,min);
|
||||
n1=CalculatePath(arena,n1,player1,player2,compteur,dist,min);
|
||||
|
||||
//Post-Traitement
|
||||
//Calcul du "poids" du chemin (nb de coups)
|
||||
dist = distance(player1->PositionX,player1->PositionY,posX,posY + 1) + n1->compteur;
|
||||
dist = distance(player1->PositionX,player1->PositionY,n1->actualX,n1->actualY ) + n1->compteur;
|
||||
|
||||
if(dist < n1->min)
|
||||
{
|
||||
n1->min=dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("n1->compteur : %i \n",n1->compteur );
|
||||
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||
if(n1->compteur == abs(player2->PositionX - player1->PositionY)-1)
|
||||
{
|
||||
printf("Chemin plus court trouvé\n");
|
||||
n1->min=n1->compteur;
|
||||
return n1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("n1->compteur : %i \n",n1->compteur );
|
||||
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||
if(n1->compteur == (abs(player2->PositionY - player1->PositionY)+abs(player2->PositionX - player1->PositionX)))
|
||||
{
|
||||
printf("Chemin plus court trouvé\n");
|
||||
//n1->min=n1->compteur;
|
||||
return n1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(((posX >= 0) && (posX < NB_BLOCS_LARGEUR ))&& ((posY - 1 >= 0) && (posY - 1 < NB_BLOCS_HAUTEUR)))
|
||||
if((((n1->actualX >= 0) && (n1->actualX < NB_BLOCS_LARGEUR ))&& ((n1->actualY - 1 >= 0) && (n1->actualY - 1 < NB_BLOCS_HAUTEUR))&& (n1->actualY -1 != n1->ParentY)))
|
||||
{
|
||||
if((n1->ParentX == player1->PositionX ) && ( n1->ParentY == player1->PositionY))
|
||||
{
|
||||
@ -396,48 +459,55 @@ NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER
|
||||
return n1;
|
||||
}
|
||||
|
||||
if((getTileTypeID(arena,posX,posY-1) == 0) && (posY - 1 != n1->ParentY))
|
||||
if((getTileTypeID(arena,n1->actualX,n1->actualY -1) == 0) && (n1->actualY - 1 != n1->ParentY))
|
||||
{
|
||||
n1->ParentY = posY - 1;
|
||||
n1->ParentX = n1->actualX ;
|
||||
n1->ParentY = n1->actualY ;
|
||||
n1->actualY = n1->actualY - 1;
|
||||
//Vers la haut
|
||||
n1->compteur = n1->compteur + 1;
|
||||
//compteur = compteur + 1;
|
||||
|
||||
//while((posX != player1->PositionX) && (posY != player1->PositionY))
|
||||
while((posX != player1->PositionX) || (posY != player1->PositionY))
|
||||
while(((n1->actualX != player1->PositionX) || (n1->actualY != player1->PositionY))&& (abs(n1->actualX - player1->PositionX) <= differenceX) && (abs(n1->actualY - player1->PositionY) <= differenceY))
|
||||
{
|
||||
n1=CalculatePath(arena,posX,posY - 1,n1,player1,player2,compteur,dist,min);
|
||||
n1=CalculatePath(arena,n1,player1,player2,compteur,dist,min);
|
||||
|
||||
//Post-Traitement
|
||||
//Calcul du "poids" du chemin (nb de coups)
|
||||
dist = distance(player1->PositionX,player1->PositionY,posX,posY - 1) + n1->compteur;
|
||||
dist = distance(player1->PositionX,player1->PositionY,n1->actualX,n1->actualY) + n1->compteur;
|
||||
|
||||
if(dist < n1->min)
|
||||
{
|
||||
n1->min=dist;
|
||||
}
|
||||
return n1;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("n1->compteur : %i \n",n1->compteur );
|
||||
printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||
|
||||
if(n1->compteur == abs(player2->PositionX - player1->PositionY)-1)
|
||||
printf("n1->compteur : %i \n",n1->compteur );
|
||||
//printf("abs(player2->PositionX - player1->PositionY)-1 : %i \n",abs(player2->PositionX - player1->PositionY)-1 );
|
||||
|
||||
if(n1->compteur ==( abs(player2->PositionX - player1->PositionX) + abs(player2->PositionY - player1->PositionY)))
|
||||
{
|
||||
printf("Chemin plus court trouvé\n");
|
||||
n1->min=n1->compteur;
|
||||
//n1->min=n1->compteur;
|
||||
return n1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("return n1\n");
|
||||
return n1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Fonction de reflexion IA fonctionne mais les pierres et arbres sont bloquants
|
||||
|
||||
|
||||
//Fonction de reflexion IA fonctionne mais les pierres et arbres sont bloquants
|
||||
/*
|
||||
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY)
|
||||
{
|
||||
printf("Player1PositionX : %i et Player1PositionY : %i \n",Player1PositionX,Player1PositionY);
|
||||
@ -449,13 +519,13 @@ int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2Posi
|
||||
|
||||
int action=0;
|
||||
|
||||
/*if(((differenceX == 1) && (differenceY == 0)) || ((differenceX == 0) && (differenceY == 1)))
|
||||
if(((differenceX == 1) && (differenceY == 0)) || ((differenceX == 0) && (differenceY == 1)))
|
||||
{
|
||||
printf("Les 2 joueur sont à coté\n");
|
||||
printf("Le joueur 2 va combattre\n");
|
||||
action = 5;
|
||||
return action;
|
||||
}*/
|
||||
}
|
||||
if(((differenceX == 1) && (differenceY == 0)) || ((differenceX == 0) && (differenceY == 1)))
|
||||
{
|
||||
printf("Attack en cours\n");
|
||||
@ -493,6 +563,6 @@ int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2Posi
|
||||
action = 0;
|
||||
}
|
||||
return action;
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* IAEngine.h
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*/
|
||||
|
||||
#ifndef IAENGINE_H_
|
||||
#define IAENGINE_H_
|
||||
|
||||
@ -7,6 +14,9 @@ typedef struct noeud
|
||||
|
||||
int ParentX;
|
||||
int ParentY;
|
||||
|
||||
int actualX;
|
||||
int actualY;
|
||||
// 'adresse' du parent (qui sera toujours dans la map fermée)
|
||||
}NOEUD;
|
||||
|
||||
@ -18,6 +28,8 @@ int distance(int x1, int y1, int x2, int y2);
|
||||
//int CalculatePath(ARENA_H_TILE* arena,int PositionX, int PositionY,PLAYER * player1, int compteur, int distance,int min);
|
||||
//int CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1, int compteur, int dist,int min);
|
||||
|
||||
NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1,PLAYER * player2, int compteur, int dist,int min);
|
||||
NOEUD * CalculatePath(ARENA_H_TILE* arena,NOEUD * n1,PLAYER * player1,PLAYER * player2, int compteur, int dist,int min);
|
||||
|
||||
//NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1,PLAYER * player2, int compteur, int dist,int min);
|
||||
//NOEUD * CalculatePath(ARENA_H_TILE* arena,int posX, int posY,NOEUD * n1,PLAYER * player1, int compteur, int dist,int min);
|
||||
#endif /* IAENGINE_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user