Skip to content
Snippets Groups Projects
Commit 185aca9d authored by maberet's avatar maberet
Browse files

commit de la qlearn pour 6720 états

parent 1c660641
No related branches found
No related tags found
No related merge requests found
CC=gcc
LDFLAG=$(shell sdl2-config --cflags --libs) -lm -lSDL2_ttf -D_REENTRANT -lSDL2_image -pthread
CFLAG=-Wall $(shell sdl2-config --cflags --libs)
LDFLAG=$(shell sdl2-config --cflags --libs) -lm -lSDL2_ttf -D_REENTRANT -lSDL2_image -pthread -g
CFLAG=-Wall $(shell sdl2-config --cflags --libs) -g
EXEC=run
SRC=$(wildcard src/*.c)
......
......@@ -8,9 +8,10 @@ int main(){
int i= 10;
srand ( time(NULL));
while (i>0){
// while (i>0){
traningAgent(100000,30, Q);
i--;}
// i--;}
//printf(" %d \n ", convertIntoZone(agent->x,agent->y));
writeQ(Q);
// running = 1;
......@@ -22,5 +23,5 @@ int main(){
// mainLoop();
mainLoop();
//mainLoop();
}
......@@ -8,7 +8,7 @@
//#include "main.h"
#define MAP_WIDTH 31
#define MAP_HEIGHT 11
#define MAP_HEIGHT 10
extern int map[MAP_HEIGHT][MAP_WIDTH];
......
......@@ -18,21 +18,36 @@ agent_t * initAgent (){
void moveAgent(agent_t * agent, int choice){
switch (choice)
{
case BACK:
agent->x += 1*agent->speed; //Avancer
break;
case BACK:
if (agent->x + 1 < (MAP_WIDTH-1) * 1)
{
agent->x += 1;
}
break;
case FOWARD:
agent->x -= 1*agent->speed; // reculer
break;
case FOWARD:
if (agent->x - 1 > (MAP_WIDTH/2 + 1) * 1)
{
agent->x -= 1;
}
break;
case UP:
agent->y += 1*agent->speed;
break;
case UP:
if (agent->y - 1 > 1)
{
agent->y -= 1;
}
break;
case DOWN:
agent->y -= 1*agent->speed;
break;
case DOWN:
if (agent->y + 1 < (MAP_HEIGHT-1) * 1)
{
agent->y += 1;
}
break;
case WAIT:
break;
}
......@@ -144,14 +159,20 @@ int argmax(float * arr){
return maxIndex;
}
// int convertIntoZone(int xAgent,int yAgent){
// int zone=0;
// xAgent=xAgent;
// yAgent=yAgent;
// if(xAgent> 15 && xAgent<23 && yAgent<=4){zone=0;}
// else if(xAgent>22 && xAgent<31 && yAgent<=4){zone=1;}
// else if(xAgent> 15 && xAgent<23 && yAgent<9){zone=2;}
// else if(xAgent> 22 && xAgent<= 31&& yAgent<9){zone=3;}
// return zone ;
// }
int convertIntoZone(int xAgent,int yAgent){
int zone=0;
xAgent=xAgent;
yAgent=yAgent;
if(xAgent> 15 && xAgent<23 && yAgent<=4){zone=0;}
else if(xAgent>22 && xAgent<31 && yAgent<=4){zone=1;}
else if(xAgent> 15 && xAgent<23 && yAgent<9){zone=2;}
else if(xAgent> 22 && xAgent<= 31&& yAgent<9){zone=3;}
zone = (yAgent-1)*14 +(xAgent -16)%14 ;
return zone ;
}
......@@ -387,6 +408,7 @@ void traningAgent ( int numberRun, int numberStep, float *****Q) {// pour avoir
reward=0;
//printf (" %d \n ", m);
while(i>0){
printf("%d %d \n ",agent->x ,agent->y );
action =takeAction(agent->x ,agent->y , Q, canonZone, zoneAngleH, zoneAngleF, greedy);
agentZone= convertIntoZone( agent->x,agent->y );
line.receiverZone= agentZone;
......
......@@ -17,7 +17,7 @@
#define NUMBER_ZONE_SHOOTER 4
#define NUMBER_ZONE_RECEIVER 4
#define NUMBER_ZONE_RECEIVER 112
#define NUMBER_ACTION 5
#define FOWARD 0//<--
......
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