Skip to content
Snippets Groups Projects
Commit d19bc68c authored by belkhiritaha's avatar belkhiritaha
Browse files

commit avant de merge avec qlearn4

parent ca6e4121
No related branches found
No related tags found
No related merge requests found
......@@ -11,5 +11,5 @@ void initEnnemy()
void manageEnnemy()
{
}
\ No newline at end of file
#include "qlearn.h"
void moveAgent(agent_t * agent, int choice){
switch (choice)
{
case BACK:
agent->x += 1*agent->speed; //Avancer
break;
case FOWARD:
agent->x -= 1*agent->speed; // reculer
break;
case UP:
agent->y += 1*agent->speed;
break;
case DOWN:
agent->y -= 1*agent->speed;
break;
case WAIT:
break;
}
}
float ***** allocateAndInitiateQ(){
int i,j,k,l,m;
float ***** q = malloc(sizeof(float ****) * NUMBER_ZONE_RECEIVER); /// alloc player zone
if (q==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for(i = 0; i < NUMBER_ZONE_RECEIVER; i++){
q[i] = malloc(sizeof(float ***) * NUMBER_ZONE_SHOOTER ); // alloc shooter zone
if (q[i]==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for(j = 0; j< NUMBER_ZONE_SHOOTER; j++){
q[i][j] = malloc(sizeof(float **) * 3 ); // alloc angle hauteur
if (q[i][j]==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for(k = 0; k <3 ; k++){
q[i][j][k] = malloc(sizeof(float *) * 5 ); // alloc angle plat
if (q[i][j][k]==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for(l = 0; l<5 ; l++){
q[i][j][k][l] = malloc(sizeof(float ) * 5); //alloc action
if (q[i][j][k][l]==NULL)
{
printf("problème d'allocation \n");
exit(1);
}
for (m=0;m <5;m++){
q[i][j][k][l][m]=0;
}
}
}
}
}
return q;
}
void writeQ(float *****Q){
int i, j, k, l, m ;
FILE * fp = fopen("q.txt", "w+");
for(i = 0; i < NUMBER_ZONE_RECEIVER; i++){
for(j = 0; j < NUMBER_ZONE_SHOOTER; j++){
for(k = 0; k < 3; k++){
for(l= 0; l < 5; l++){
for(m= 0; m <5; m++){
fprintf(fp, "%f ", Q[i][j][k][l][m]);
}
}
}
fprintf(fp, "\n");
}
fprintf(fp, "\n");
}
fflush(fp);
fclose(fp);
}
\ No newline at end of file
#ifndef Q_LEARN
#define Q_LEARN
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#include "ball.h"
#include "math.h"
#include "map.h"
#define NUMBER_ZONE_SHOOTER 4
#define NUMBER_ZONE_RECEIVER 4
#define FOWARD 0//<--
#define BACK 1 //-->
#define UP 2
#define DOWN 3
#define WAIT 4
typedef struct agent {
int x;
int y;
int heigth;
int weight;
int speed;
} agent_t;
void moveAgent(agent_t * agent, int choice);
float ***** allocateAndInitiateQ();
void writeQ(float *****Q);
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment