122 lines
3.0 KiB
C
122 lines
3.0 KiB
C
/*
|
|
* 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"
|
|
|
|
#include "SDL2/SDL.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
|
|
|
|
int IAEngine(ARENA_H_TILE* arena,PLAYER * player1, PLAYER * player2)
|
|
{
|
|
//Fonction avec seulement 2 joueurs, voir la gestion quand il y a 2 IA supplémentaire
|
|
//Player 1 est le joueur, player 2 le bot
|
|
|
|
|
|
if((player1 != NULL) & (player2 !=NULL))
|
|
{
|
|
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur
|
|
|
|
int action;
|
|
|
|
action = FindShortestPath(player1->PositionX,player1->PositionY,player2->PositionX,player2->PositionY);
|
|
|
|
printf("Tour de l'IA\n");
|
|
if(action == 5)
|
|
{
|
|
AttackPlayer(player1,player2);
|
|
}
|
|
else if ((action >= 1) && (action <= 4))
|
|
{
|
|
ActionPlayer(arena,player2,action);
|
|
}
|
|
//On vérifie si les 2 joueurs sont à côté pour attaquer
|
|
printf("Vérification position\n");
|
|
action = FindShortestPath(player1->PositionX,player1->PositionY,player2->PositionX,player2->PositionY);
|
|
if(action == 5)
|
|
{
|
|
AttackPlayer(player2,player1);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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);
|
|
printf("Player2PositionX : %i et Player2PositionY : %i \n",Player2PositionX,Player2PositionY);
|
|
int differenceX = abs(Player1PositionX - Player2PositionX);
|
|
int differenceY = abs(Player1PositionY - Player2PositionY);
|
|
|
|
printf("DifferenceX : %i et DifferenceY : %i \n",differenceX,differenceY);
|
|
|
|
int action=0;
|
|
|
|
/*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");
|
|
return action = 5;
|
|
}
|
|
|
|
else if(differenceX > abs(Player1PositionX - (Player2PositionX - 1)))
|
|
//if(differenceX > abs(Player1PositionX - (Player2PositionX - 1)))
|
|
{
|
|
printf("Chemin plus court sur X gauche\n");
|
|
printf("Le joueur 2 va vers la gauche\n");
|
|
action = 4;
|
|
}
|
|
else if(differenceX > abs(Player1PositionX - (Player2PositionX + 1)))
|
|
{
|
|
printf("Chemin plus court sur X droite\n");
|
|
printf("Le joueur 2 va vers la droite\n");
|
|
action = 2;
|
|
}
|
|
else if(differenceY > abs(Player1PositionY - (Player2PositionY + 1)))
|
|
{
|
|
printf("Chemin plus court sur Y\n");
|
|
printf("Le joueur 2 va vers le bas\n");
|
|
action = 3;
|
|
}
|
|
else if(differenceY > abs(Player1PositionY - (Player2PositionY - 1)))
|
|
{
|
|
printf("Chemin plus court sur Y\n");
|
|
printf("Le joueur 2 va vers le haut\n");
|
|
action = 1;
|
|
}
|
|
else
|
|
{
|
|
printf("Chemin plus long\n");
|
|
action = 0;
|
|
}
|
|
return action;
|
|
|
|
}
|
|
|