99 lines
2.4 KiB
C
99 lines
2.4 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 "SDL2/SDL.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
|
|
|
|
int IAEngine(PLAYER * player1, PLAYER * player2)
|
|
{
|
|
//Player 1 est le joueur, player 2 le bot
|
|
if((player1 != NULL) & (player2 !=NULL))
|
|
char Race[20];
|
|
{
|
|
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur
|
|
int Player1PositionX = player1->PositionX;
|
|
int Player1PositionY = player1->PositionY;
|
|
|
|
int Player2PositionX = player2->PositionX;
|
|
int Player2PositionY = player2->PositionY;
|
|
int action;
|
|
|
|
action = FindShortestPath(Player1PositionX,Player1PositionY,Player2PositionX,Player2PositionY);
|
|
|
|
printf("Tour de l'IA\n");
|
|
if(action == 5)
|
|
{
|
|
AttackPlayer(player1,player2);
|
|
}
|
|
else if ((action >= 1) && (action <= 4))
|
|
{
|
|
ActionPlayer(player2,action);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY)
|
|
{
|
|
int differenceX = abs(Player1PositionX - Player2PositionX);
|
|
int differenceY = abs(Player1PositionY - Player2PositionY);
|
|
|
|
int action;
|
|
|
|
|
|
//Revoir cette partie il faut que les 2 joueurs soit sur la même ligne ou colone avec une différence de ligne ou colonne de 1
|
|
if((abs(Player1PositionX - (Player2PositionX - 1)) == 1) ||
|
|
(abs(Player1PositionX - (Player2PositionX + 1)) == 1) ||
|
|
(abs(Player1PositionX - (Player2PositionY - 1)) == 1) ||
|
|
(abs(Player1PositionX - (Player2PositionY + 1)) == 1))
|
|
{
|
|
printf("Les 2 joueur sont à coté\n");
|
|
printf("Le joueur 2 va combattre\n");
|
|
action = 5;
|
|
}
|
|
|
|
if(differenceX > abs(Player1PositionX - (Player2PositionX - 1)))
|
|
{
|
|
printf("Chemin plus court sur X\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\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;
|
|
|
|
}
|
|
|