Skip to content
Snippets Groups Projects
Commit 066b5f3c authored by maberet's avatar maberet
Browse files

commit des piles et zones fonctionnelles

parent 7ef21b2f
No related branches found
No related tags found
No related merge requests found
......@@ -8,11 +8,4 @@
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
\ No newline at end of file
#include "ball.h"
//ball_t ball;
int trajectoireAntoine[NUMBERPOINT_TRAJEC][2];
void initBall()
{
point_t initCanon (point_t canon){
canon.x=(1+rand()%14)*BLOCK_SIZE;
canon.y=(1+rand()%8)*BLOCK_SIZE;
return canon;
}
float defineAngle(int canonX, int canonY, int xDropPoint, int yDropPoint)
point_t initDropPoint (point_t dropPoint){
dropPoint.x=(16+rand()%14)*BLOCK_SIZE;
dropPoint.y=(1+rand()%8)*BLOCK_SIZE;
return dropPoint;
}
float defineAngleF(int canonX, int canonY, int xDropPoint, int yDropPoint)
{
float distance;
float angleSin;
canonX=canonX/BLOCK_SIZE;
canonY=canonY/BLOCK_SIZE;
xDropPoint= xDropPoint/BLOCK_SIZE;
yDropPoint= yDropPoint/BLOCK_SIZE;
distance = sqrtf(powf((float)(xDropPoint - canonX), 2) + powf((float)(yDropPoint - canonY), 2));
angleSin = asinf(distance / (xDropPoint - canonX));
angleSin = asinf(((float) (yDropPoint - canonY))/distance);
return angleSin;
}
float defineAngleH(int xCanon, int xDropPoint){
int xNet =15 ;
int yNet= 4;
float angle ;
float yTemp;
xCanon= xCanon/BLOCK_SIZE;
xDropPoint=xDropPoint/BLOCK_SIZE;
yTemp = lagrangeInterpolation((float)(xCanon+(xDropPoint-xCanon)/4), xCanon , 2,xNet , yNet , xDropPoint, 0 );
angle= atanf( (float)(yTemp/ (xCanon+(xDropPoint-xCanon)/4) )) ; // possible faute ?
return angle;
}
/*
* Fonction qui prend une valeur de x et 3 points. Elle
* renvoie la coordonnée y liée à la valeur de x sur la
......@@ -25,7 +51,7 @@ float defineAngle(int canonX, int canonY, int xDropPoint, int yDropPoint)
* Point n°2 (filet ) : int xf, int yf
* Point n°3 (target) : int xt, int yt
*/
int lagrangeInterpolation(float xp, int xd, int yd, int xf, int yf, int xt, int yt)
float lagrangeInterpolation(float xp, int xd, int yd, int xf, int yf, int xt, int yt)
{
float x[4], y[4], yp = 0, p;
int i, j, n;
......
......@@ -5,13 +5,16 @@
#include <time.h>
#include <stdio.h>
#include <math.h>
#include "render.h"
#define NUMBERPOINT_TRAJEC 50
typedef enum
{
false,
true
false, true
} booleen_t;
typedef struct ball
......@@ -23,13 +26,20 @@ typedef struct ball
float speed;
} ball_t;
typedef struct point{
int x;
int y;
} point_t ;
//extern ball_t ball;
extern int trajectoireAntoine[NUMBERPOINT_TRAJEC][2];
void initBall();
float defineAngle(int, int, int, int);
point_t initCanon (point_t canon);
point_t initDropPoint (point_t dropPoint);
float defineAngleF(int, int, int, int);
float defineAngleH(int xCanon, int xDropPoint);
int lagrangeInterpolation(float, int, int, int, int, int, int);
float lagrangeInterpolation(float, int, int, int, int, int, int);
void calculTrajectoireAntoine2(int, int, int, int, int, int);
#endif
\ No newline at end of file
......@@ -5,15 +5,13 @@ int game_state;
int main(){
agent_t * agent;
int i ;
float ***** Q = allocateAndInitiateQ();
srand ( time(NULL));
agent =initAgent();
writeQ(Q);
running = 1;
i=setReward( agent->x , agent->y, 0);
printf("%d \n ",i );
game_state = GAME;
readMapFromFile("map.txt");
initPlayer();
......
......@@ -5,7 +5,7 @@
#define MAP_WIDTH 31
#define MAP_HEIGHT 18
#define MAP_HEIGHT 11
extern int map[MAP_HEIGHT][MAP_WIDTH];
......
......@@ -7,7 +7,7 @@ agent_t * initAgent (){
exit (1);
}
agent->x=(16+rand()%14)*BLOCK_SIZE;
agent->y=(1+rand()%14)*BLOCK_SIZE;
agent->y=(1+rand()%8)*BLOCK_SIZE;
agent->high=2*BLOCK_SIZE;
agent->weight=2*BLOCK_SIZE;
agent->speed = 1;
......@@ -131,10 +131,21 @@ int convertIntoZone(int xAgent,int yAgent){
int zone;
xAgent=xAgent/BLOCK_SIZE;
yAgent=yAgent/BLOCK_SIZE;
if(xAgent<23 && yAgent<=8){zone=0;}
else if(xAgent<31 && yAgent<=8){zone=1;}
else if(xAgent<23 && yAgent<=18){zone=2;}
else if(xAgent< 31&& yAgent<18){zone=3;}
if(xAgent<23 && yAgent<=4){zone=0;}
else if(xAgent<31 && yAgent<=4){zone=1;}
else if(xAgent<23 && yAgent<9){zone=2;}
else if(xAgent< 31&& yAgent<9){zone=3;}
return zone ;
}
int convertIntoZoneCanon(int xCanon,int yCanon){
int zone;
xCanon=xCanon/BLOCK_SIZE;
yCanon=yCanon/BLOCK_SIZE;
if(xCanon<9 && yCanon<=4){zone=0;}
else if(xCanon<15 && yCanon<=4){zone=1;}
else if(xCanon<9 && yCanon<9){zone=2;}
else if(xCanon<15&& yCanon<9){zone=3;}
return zone ;
}
......@@ -214,28 +225,6 @@ int takeAction(int xAgent, int yAgent, float ***** Q, int canonZone, int angleHZ
return action;
}
void insertPointToLine(ptline_t head, int receiverZone, int canonZone, int angleHZone, int angleFZone){
ptline_t newPoint = (ptline_t )malloc(sizeof(line_t));
if (newPoint==NULL){
printf("error malloc\n ");
exit(1);
}
newPoint->receiverZone = receiverZone;
newPoint->shooterZone = canonZone;
newPoint-> angleHZone= angleHZone;
newPoint->angleFZone=angleFZone;
newPoint->next =head;// problème pt
head = newPoint;
}
void freeLine ( ptline_t headLine){
ptline_t current= headLine;
while ( current !=NULL){
ptline_t temporary = current;
current = current ->next;
free(temporary);
}
}
int setReward(int xAgent, int yAgent, int dropZone){
int zoneAgent;
......@@ -248,27 +237,98 @@ int setReward(int xAgent, int yAgent, int dropZone){
return (reward);
}
float defineAngle (int xCanon, int yCanon , int xDropPoint, int yDropPoint){
float distance;
float angleSin;
distance= sqrtf( powf((float)(xDropPoint-xCanon),2)+powf((float)(yDropPoint-yCanon),2));
angleSin = asinf(distance/(xDropPoint-xCanon));
return angleSin;
stack_t* initStack(int numberelt){
stack_t *stack=NULL;
stack=(stack_t *)malloc(sizeof(stack_t)); // allocation du ptr de tête.
if (stack==NULL){ // vérification de l'allocation.
printf("problème d'allocation\n");
exit(1);
}
void traningAgent ( int numberRun, int numberStep, float *****Q) {
int i ;
int action;
point_t canon ;
point_t dropPoint ;
stack->base = (line_t *) malloc(numberelt*sizeof(line_t));// allocation de la stack de longueur numberelt.
if (stack->base==NULL){
printf("problème d'allocation\n");
exit(1);
}
stack->numberelt=numberelt; //ajout du nombre d'élément insérable dans la file.
stack->top=-1; //initialisation de l'indice du dernier élément.
return (stack);
}
int emptyStack(stack_t *stack){
int result =0;
if (stack->top==-1){ // test de l'indice du top.
result=1; // la stack est vide.
}
while (numberRun>0){
canon=initPoint(0);
dropPoint= initPoint(1);
for (i=0; i< numberStep;i++){
return (result);
}
int fullStack(stack_t *stack)
{
int result = 0;
if (stack->numberelt == (stack->top)+1) //si le top est l'indice du dernier élément élément de la stack
{
result = 1;
}
return result;
}
void actionStack(stack_t *stack, line_t element)
{
if(!fullStack(stack)) //si la stack n'est pas pleine
{
stack->base[(stack->top)+1] = element; //on ajoute l'élément à l'indice top+1
stack->top = stack->top+1; //on incrémente l'indice du top
}
else
{
printf("Pile pleine\n" );
}
}
line_t unStack(stack_t *stack)
{
line_t top;
if(!emptyStack(stack)) //si la stack n'est pas vide
{
top = stack->base[stack->top]; //on récupère le top
stack->top = stack->top-1; //on décrémente l'indice du top
}
else
{
printf("Pile vide");
}
return top;
}
void freeStack(stack_t *stack)
{
if(stack != NULL)
{
free(stack->base); //on libère le tableau dynamique
free(stack); //on libère la tête de la stack
printf("Pile libérée\n");
}
else
{
printf("Libération impossible, stack == NULL\n");
}
}
......@@ -4,12 +4,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#include "ball.h"
#include "ball.h"
#include "math.h"
#include "map.h"
#define M_PI 3.14159265358979323846
#define LEARN_RATE 0.9
#define NUMBER_ZONE_SHOOTER 4
#define NUMBER_ZONE_RECEIVER 4
#define NUMBER_ACTION 5
......@@ -20,6 +22,7 @@
#define DOWN 3
#define WAIT 4
typedef struct agent {
int x;
int y;
......@@ -33,14 +36,18 @@ typedef struct line {
int shooterZone;
int angleHZone;
int angleFZone;
struct line *next ;
int action;
int reward;
}line_t;
}line_t,*ptline_t;
typedef struct stack
{
line_t *base;
int numberelt;
int top;
} stack_t;
typedef struct point{
int x;
int y;
} point_t ;
agent_t* initAgent ( );
......@@ -49,10 +56,16 @@ float ***** allocateAndInitiateQ();
void writeQ(float *****);
int argmax(float * );
int convertIntoZone(int ,int y);
int convertIntoZoneCanon(int xCanon,int yCanon);
int converterIntoAngleF(float);
int converterIntoAngleH(float);
int takeAction(int ,int , float ***** , int , int, int, float );
void insertPointToLine(ptline_t head, int, int , int , int);
void freeLine ( ptline_t makeheadLine);
int setReward(int , int , int );
stack_t* initStack (int nbelt);
int emptyStack (stack_t *stack);
int fullStack(stack_t *stack);
void actionStack(stack_t *stack, line_t line);
line_t unStack(stack_t *stack);
void freeStack(stack_t *stack);
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment