diff --git a/.gitignore b/.gitignore index f42a7a25a82ef0c5c6854f39348ae72acc178e2f..0ea84be7280fc7d0d34ea7cc97422ef7f3312bed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ run +q.txt # Prerequisites *.d diff --git a/README.md b/README.md index fc675533ef5bc9aff1b252c914066bc570f6184b..b3b5717bcc1d9fdb0dd46c40dac7d214b80e3264 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ Trello : https://trello.com/b/YGhNeYX3/projet-apprentissage-par-renforcement │ │ └── Animate │ ├── Beret │ │ ├── snakes -│ │ └── x_fenetre +│ │ ├── x_fenetre +| | ├── jeu_de_la_vie +| | └── sprites │ └── Meyer │ ├── x_fenetre │ ├── pave_de_serpents @@ -28,5 +30,15 @@ Trello : https://trello.com/b/YGhNeYX3/projet-apprentissage-par-renforcement │ └── animation_sprites └── travail_de_groupe ├── chef_oeuvre + | ├── bin + | | └── [fichiers .o] + | ├── Res + | | └── [fichiers .png et .ttf] + | ├── src + | | ├── [fichiers .c] + | | └── [fichiers .h] + | ├── Makefile + | ├── markov.txt + | └── map.txt └── jeu_appren_par_renfo ``` diff --git a/travail_de_groupe/chef_oeuvre/chef_oeuvre.odt b/travail_de_groupe/chef_oeuvre/chef_oeuvre.odt index be89ba4f6298e709c64f98ccc8d6db6f0d61adb1..77877a1e826490e63324f023afbf6e01b538e8f7 100644 Binary files a/travail_de_groupe/chef_oeuvre/chef_oeuvre.odt and b/travail_de_groupe/chef_oeuvre/chef_oeuvre.odt differ diff --git a/travail_de_groupe/chef_oeuvre/map.txt b/travail_de_groupe/chef_oeuvre/map.txt index c51768ad563b4584a14438de0d2875e494484610..18e6623a541bcf5a7327f90fadd0eb3d6433a629 100644 --- a/travail_de_groupe/chef_oeuvre/map.txt +++ b/travail_de_groupe/chef_oeuvre/map.txt @@ -1,20 +1,20 @@ -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1 1 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 -0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 1 0 0 0 -0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 -2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 \ No newline at end of file +0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 2 2 2 2 +0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 2 2 +0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 2 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 +1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 +0 0 0 1 0 0 0 0 2 2 0 0 0 0 0 0 1 1 0 0 +0 0 0 1 0 0 0 0 2 2 0 0 0 0 0 0 1 1 0 0 +0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 +0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +2 2 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 2 2 +2 2 2 2 0 0 0 0 0 0 1 1 1 0 0 0 0 0 2 2 +2 2 2 2 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 \ No newline at end of file diff --git a/travail_de_groupe/chef_oeuvre/markov.txt b/travail_de_groupe/chef_oeuvre/markov.txt index 4c18679d32b93424c3e4f46eebd8ecb1a43df08a..7b171fb51e70fa70daefd7e3690c285531fb7a75 100644 --- a/travail_de_groupe/chef_oeuvre/markov.txt +++ b/travail_de_groupe/chef_oeuvre/markov.txt @@ -1,5 +1,5 @@ 50 50 0 0 0 -0 60 40 0 0 -0 10 70 20 0 -0 0 10 50 40 +0 30 70 0 0 +0 10 50 40 0 +0 0 10 40 50 0 0 0 50 50 diff --git a/travail_de_groupe/chef_oeuvre/src/fire.c b/travail_de_groupe/chef_oeuvre/src/fire.c index 08b6a2fb755f6fe754c0e4dba738f30728e002a7..ce1f573300e208a21c4040ac130f3d43ef1ba8e0 100644 --- a/travail_de_groupe/chef_oeuvre/src/fire.c +++ b/travail_de_groupe/chef_oeuvre/src/fire.c @@ -36,6 +36,9 @@ listchainfire_t insertAheadFire(fire_t fire,listchainfire_t listFire) m->next= listFire; listFire=m; } + else { + free(m); + } return listFire; } @@ -57,7 +60,7 @@ listchainfire_t startFire(listchainfire_t listFire,int numberFire, int mapSize){ yFire= rand()%mapSize; fire.x= xFire; fire.y= yFire; - fire.state=1; + fire.state=2; listFire=insertAheadFire(fire, listFire); @@ -217,8 +220,19 @@ listchainfire_t probabilitySpreadFire( listchainfire_t listFire, listchainfire_t return listFire; } +void burnTree (listchainfire_t listFire){ + listchainfire_t listTemporary = listFire; + + while (!emptyListFire(listTemporary)){ + if (map[(listTemporary->fire).y][(listTemporary->fire).x]==TREE){map[(listTemporary->fire).y][(listTemporary->fire).x]=0;} + } +} + listchainfire_t spreadFire (listchainfire_t listFire){ listchainfire_t listTemporary=fireList; + + //burnTree(listFire); + srand(time(NULL)); while (!emptyListFire(listTemporary)){ if ((listTemporary->fire).state==4){ @@ -232,13 +246,8 @@ listchainfire_t spreadFire (listchainfire_t listFire){ booleen_t winGame(listchainfire_t listFire){ booleen_t win = true; - listchainfire_t listTemporary= listFire; + + if(!emptyListFire(listFire)){win=false;} - while (!emptyListFire( listTemporary)){ - if ((listTemporary->fire).state!=0){ - win= false; - break; - } - } return win; } \ No newline at end of file diff --git a/travail_de_groupe/chef_oeuvre/src/fire.h b/travail_de_groupe/chef_oeuvre/src/fire.h index 0284cedffa35689e462c662c6493532d8e1dd92b..125c761db9d63acd407f71b8c87b0cb8bc7b3761 100644 --- a/travail_de_groupe/chef_oeuvre/src/fire.h +++ b/travail_de_groupe/chef_oeuvre/src/fire.h @@ -13,7 +13,7 @@ #define STRONG 3 #define SPREAD 4 -#define UPDATETIME 5 +#define UPDATETIME 3 typedef struct fire{ @@ -51,6 +51,7 @@ void nextFire(listchainfire_t ); listchainfire_t probabilitySpreadFire( listchainfire_t, listchainfire_t); listchainfire_t spreadFire (listchainfire_t ); booleen_t winGame(listchainfire_t ); +void burnTree (listchainfire_t listFire); diff --git a/travail_de_groupe/chef_oeuvre/src/gest_event.c b/travail_de_groupe/chef_oeuvre/src/gest_event.c index 3db27bee0477d6f82dd284ad0f9c2ba9f582d951..6174f178dc61534cae30d5a00b0ffcf1b05e454c 100644 --- a/travail_de_groupe/chef_oeuvre/src/gest_event.c +++ b/travail_de_groupe/chef_oeuvre/src/gest_event.c @@ -203,6 +203,7 @@ void manageGame(){ } } updatePlayer(); + //burnTree(fireList); SDL_Delay(5); } diff --git a/travail_de_groupe/chef_oeuvre/src/render.c b/travail_de_groupe/chef_oeuvre/src/render.c index 6904be221db33d98a16daa8fec223c6fc9a813c5..dc3d38efa588dec5f82fb7a6289b34f1fcd969fd 100644 --- a/travail_de_groupe/chef_oeuvre/src/render.c +++ b/travail_de_groupe/chef_oeuvre/src/render.c @@ -1,6 +1,7 @@ #include "render.h" float timer = 0; +int fps; SDL_Window *window; SDL_Renderer *renderer; @@ -113,6 +114,50 @@ void createWindow(){ } +void endSDL(){ + SDL_DestroyTexture(grassTexture); + SDL_DestroyTexture(treeTexture); + SDL_DestroyTexture(hoverTexture); + SDL_DestroyTexture(noHoverTexture); + SDL_DestroyTexture(playerTexture); + SDL_DestroyTexture(playerIdleTexture); + SDL_DestroyTexture(backgroundTexture); + SDL_DestroyTexture(backgroundSidesTexture); + SDL_DestroyTexture(backgroundLostTexture); + SDL_DestroyTexture(playButtonTexture); + SDL_DestroyTexture(playButtonHoverTexture); + SDL_DestroyTexture(playAgainButtonTexture); + SDL_DestroyTexture(playAgainButtonHoverTexture); + SDL_DestroyTexture(quitButtonTexture); + SDL_DestroyTexture(quitButtonHoverTexture); + SDL_DestroyTexture(fireTexture); + SDL_DestroyTexture(waterTexture); + SDL_DestroyTexture(emptyBucketTexture); + SDL_DestroyTexture(filledBucketTexture); + SDL_DestroyTexture(heartTexture); + SDL_DestroyTexture(scoreTexture); + SDL_DestroyTexture(nextFireTexture); + SDL_DestroyTexture(backgroundWonTexture); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + TTF_CloseFont(robotoFont); + TTF_Quit(); + SDL_Quit(); + if (gameState != WON){ + fireList = freeListFire(fireList); + } +} + +void drawString(char *text, int x, int y, int w, int h, int r, int g, int b, int a){ + SDL_Color color = {r, g, b, a}; + SDL_Surface *surface = TTF_RenderText_Solid(robotoFont, text, color); + SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_Rect rect = {x, y, surface->w, surface->h}; + SDL_RenderCopy(renderer, texture, NULL, &rect); + SDL_FreeSurface(surface); + SDL_DestroyTexture(texture); +} + void drawBackground(){ SDL_Rect rect = {0, 0, screenDimension.w, screenDimension.h}; SDL_RenderCopy(renderer, backgroundTexture, NULL, &rect); @@ -306,10 +351,7 @@ void drawScore(){ rect.y += rect.h; char str[10]; sprintf(str, "%d", player.score); - SDL_Color textColor = {237,222,17}; - SDL_Surface * surface = TTF_RenderText_Solid(robotoFont, str, textColor); - SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface); - SDL_RenderCopy(renderer, texture, NULL, &rect); + drawString(str, rect.x, rect.y, (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2, screenDimension.h/6,237,222,17,255); } void drawTime(){ @@ -321,12 +363,21 @@ void drawTime(){ SDL_RenderCopy(renderer, nextFireTexture, NULL, &rect); rect.y += rect.h; char str[10]; - printf("%d\n", (UPDATETIME * 1000 - (int)timer % (UPDATETIME * 1000))/1000); + //printf("%d\n", (UPDATETIME * 1000 - (int)timer % (UPDATETIME * 1000))/1000); sprintf(str, "%d", (UPDATETIME * 1000 - (int)timer % (UPDATETIME * 1000))/1000); - SDL_Color textColor = {237,222,17}; - SDL_Surface * surface = TTF_RenderText_Solid(robotoFont, str, textColor); - SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface); - SDL_RenderCopy(renderer, texture, NULL, &rect); + drawString(str, rect.x, rect.y, (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2, screenDimension.h/6,237,222,17,255); +} + +void drawFPS(){ + SDL_Rect rect; + int h = screenDimension.h/12; + int w = screenDimension.w/12; + int x = (screenDimension.w + (MAPSIZE * CELLSIZE)) / 2; + int y = screenDimension.h - rect.h; + + char str[10]; + sprintf(str, "%d", fps); + drawString(str, x, y, w, h,237,222,17,255); } void drawGame(){ @@ -339,6 +390,7 @@ void drawGame(){ drawPlayerHP(); drawScore(); drawTime(); + drawFPS(); SDL_RenderPresent(renderer); } @@ -353,7 +405,15 @@ void drawLost(){ SDL_RenderCopy(renderer, playAgainButtonHoverTexture, NULL, &rect); SDL_RenderCopy(renderer, quitButtonHoverTexture, NULL, &rect); SDL_RenderCopy(renderer, playAgainButtonHoverTexture, NULL, &rect); - SDL_RenderPresent(renderer); + + // draw score + rect.h = screenDimension.h/12; + rect.w = rect.h; + rect.x = screenDimension.w/2; + rect.y = screenDimension.h/2 - rect.h; + char str[10]; + sprintf(str, "%d", player.score); + drawString(str, rect.x, rect.y, rect.w, rect.h,237,222,17,255); } void drawWon(){ @@ -366,7 +426,15 @@ void drawWon(){ SDL_RenderCopy(renderer, playAgainButtonHoverTexture, NULL, &rect); SDL_RenderCopy(renderer, quitButtonHoverTexture, NULL, &rect); SDL_RenderCopy(renderer, playAgainButtonHoverTexture, NULL, &rect); - SDL_RenderPresent(renderer); + + // draw score + rect.h = screenDimension.h/12; + rect.w = rect.h; + rect.x = screenDimension.w/2; + rect.y = screenDimension.h/2 - rect.h; + char str[10]; + sprintf(str, "%d", player.score); + drawString(str, rect.x, rect.y, rect.w, rect.h,237,222,17,255); } void mainLoop(){ @@ -488,8 +556,9 @@ void mainLoop(){ a = SDL_GetTicks(); delta = (a - b); if (delta > 1000/FPS_TO_GET){ + fps = 1000/delta; timer += delta; - printf("%d\n", (int)timer % 1000); + //printf("%d\n", (int)timer % 1000); b = a; switch (gameState){ case MENU: @@ -520,6 +589,6 @@ void mainLoop(){ // fait dormir le thread pour garder des ressources usleep(1000 * (1000/FPS_TO_GET - delta)); } - } + endSDL(); } \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/map.txt b/travail_de_groupe/jeu_appren_par_renfo/map.txt new file mode 100644 index 0000000000000000000000000000000000000000..d6e01f65207317b588d271d05e59c8c595a4dd00 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/map.txt @@ -0,0 +1,17 @@ +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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 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 1 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 1 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 1 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 1 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 1 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 1 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 0 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 0 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 1 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 1 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 1 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 1 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 1 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 1 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 diff --git a/travail_de_groupe/jeu_appren_par_renfo/moving_ball/.vscode/settings.json b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..0f06797c840400ab1e6cf56e1ad97bdd701cfe39 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "stdio.h": "c" + } +} \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/moving_ball/Makefile b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0826868a1a4e3c39362aac62d470f3b85032fab8 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/Makefile @@ -0,0 +1,23 @@ +CC=gcc + +LDFLAG=$(shell sdl2-config --cflags --libs) -lm -lSDL2_ttf -D_REENTRANT -lSDL2_image -pthread +CFLAG=-Wall $(shell sdl2-config --cflags --libs) + +EXEC=run +SRC=$(wildcard src/*.c) +OBJ=$(SRC:.c=.o) + +all:$(EXEC) + +$(EXEC):$(OBJ) + $(CC) -o $@ $^ $(LDFLAG) + mv $^ bin/ + +%.o:%.c + $(CC) -o $@ -c $< $(CFLAG) + +.PHONY:clean + +clean: + rm -rf bin/*.o + rm -rf $(EXEC) \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/moving_ball/map.txt b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/map.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f395db64a1843d91274c93cc07667143ab9bc7c --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/map.txt @@ -0,0 +1,20 @@ +3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 +3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 +3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 +3 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 3 +3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 3 +3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 3 +3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 3 +3 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 3 +3 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 3 +1 1 1 1 1 1 1 1 1 2 1 1 0 0 0 0 0 0 0 3 +1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 3 +1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 3 +1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 3 +1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 3 +1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 3 +1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 3 +1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 3 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 +1 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 3 +3 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/moving_ball/map2.txt b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/map2.txt new file mode 100644 index 0000000000000000000000000000000000000000..f170339be6de88c0d283320c93a2877e62efab41 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/map2.txt @@ -0,0 +1,4 @@ +1 0 0 0 +1 1 0 0 +1 1 1 0 +0 0 1 2 \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/moving_ball/q.txt b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/q.txt new file mode 100644 index 0000000000000000000000000000000000000000..93b39d4b84e44c63c723d8fa9f2e3885e8e47523 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/q.txt @@ -0,0 +1,420 @@ +-5.243739 -inf -5.377914 -inf +-5.429800 -5.169731 -5.176440 -inf +-5.165913 -5.301606 -5.199240 -inf +-5.093489 -4.987607 -5.124341 -inf +-4.829218 -5.138169 -4.795535 -inf +-4.893990 -4.866118 -4.821217 -inf +-4.794188 -4.842797 -4.921136 -inf +-4.800076 -4.721111 -4.667508 -inf +-4.893199 -4.728502 -4.736252 -inf +-4.918698 -4.940613 -4.671112 -inf +-4.818871 -5.289957 -4.428394 -inf +-5.104024 -5.779325 -3.709882 -inf +-5.148765 -5.118306 -3.709961 -inf +-5.110335 -5.223148 -3.709913 -inf +-5.123065 -5.210318 -3.709907 -inf +-5.733078 -5.176024 -3.709600 -inf +-6.351624 -5.160927 -4.609354 -inf +-6.532470 -5.786995 -5.413912 -inf +-6.410418 -6.164696 -6.094768 -inf +-inf -6.644084 -6.802499 -inf + +-5.386274 -inf -5.385622 -5.141302 +-5.335995 -5.137397 -5.148215 -5.158483 +-5.001960 -4.982563 -4.947537 -5.216639 +-4.262907 -4.317315 -4.251924 -4.256180 +-4.252142 -4.057907 -4.102102 -4.272632 +-4.164576 -4.136004 -4.198442 -4.136745 +-4.078363 -4.144362 -4.030284 -4.276768 +-3.956133 -3.989723 -3.938843 -4.134250 +-3.733403 -3.896568 -3.758005 -4.248070 +-3.421112 -3.665032 -3.418931 -3.897395 +-2.710000 -3.945012 -2.709999 -4.891057 +-2.709992 -3.438846 -1.887332 -4.338290 +-2.709774 -2.709977 -1.900000 -4.338088 +-2.709892 -2.709526 -1.900001 -4.337984 +-2.709050 -2.709764 -1.900000 -4.338062 +-3.608963 -2.709252 -1.900000 -4.334743 +-5.418305 -3.709816 -2.899999 -6.144703 +-6.142814 -4.608118 -3.800000 -6.833059 +-7.277441 -5.402278 -4.609997 -7.065204 +-inf -6.099299 -6.100728 -7.254202 + +-5.100510 -inf -5.132390 -5.241182 +-4.862952 -4.929137 -4.820026 -5.146064 +-4.171716 -4.395895 -4.180595 -4.251078 +-4.151543 -4.137047 -4.118487 -4.167108 +-4.052727 -4.177018 -4.069291 -4.053590 +-4.099039 -4.051290 -4.073980 -3.993464 +-3.916485 -3.962617 -3.949132 -3.910439 +-3.791988 -3.699055 -3.713235 -3.792525 +-3.381916 -3.539104 -3.385313 -3.799403 +-2.709994 -3.751859 -2.701937 -3.939222 +-1.851373 -3.438970 -1.900000 -3.438997 +-1.900001 -2.703229 -0.767699 -2.710000 +-1.900001 -1.900000 -1.000000 -2.709999 +-1.900001 -1.900000 -1.000000 -2.710000 +-1.900001 -1.900001 -1.000000 -2.709999 +-1.900001 -1.900000 -1.000000 -2.709999 +-2.800000 -1.900000 -1.000000 -3.609998 +-4.609997 -2.899999 -2.000001 -5.419998 +-6.148661 -3.799996 -2.899999 -6.148919 +-inf -4.609928 -4.609920 -7.298321 + +-4.870554 -inf -4.947193 -5.149903 +-3.965417 -4.321782 -4.002220 -4.034471 +-3.939150 -3.960008 -3.897385 -4.085763 +-3.925844 -3.892177 -3.926335 -3.903955 +-3.913253 -3.897762 -3.899579 -3.953223 +-3.881472 -3.858325 -3.868976 -3.840844 +-3.713982 -3.755480 -3.742694 -3.883584 +-3.338329 -3.655680 -3.424896 -3.541014 +-2.703450 -3.434459 -3.138285 -3.725963 +-1.851567 -3.434393 -2.700996 -3.436843 +-0.700419 -2.709999 -1.871160 -2.709593 +-0.000000 -0.844696 0.753925 -0.874741 +-0.000000 -0.000000 -0.900001 -0.900001 +-0.000000 -0.000000 -0.900001 -0.900001 +-0.000000 -0.000000 -0.900001 -0.900001 +-0.000000 -0.000000 -0.900001 -0.900001 +-0.000000 -0.000000 -0.900001 -0.900001 +-0.900001 -0.000000 -0.900001 -1.800000 +-3.609998 -1.000000 -2.710000 -3.609998 +-inf -2.899999 -5.338695 -6.142961 + +-4.492912 -inf -4.692348 -4.853301 +-3.788161 -3.995793 -3.730420 -3.747780 +-3.749786 -3.707524 -3.720836 -3.781657 +-3.677212 -3.730814 -3.641507 -3.671039 +-3.587251 -3.558038 -3.564804 -3.824237 +-3.506508 -3.543908 -3.488388 -3.757974 +-3.449353 -3.489921 -3.420201 -3.485045 +-3.184022 -3.310478 -3.216944 -3.201053 +-2.684212 -2.953734 -2.993634 -2.976157 +-1.786383 -3.381642 -2.654029 -2.680264 +-0.356285 -2.707830 -1.806944 -1.860847 +-0.893784 -0.774323 1.516277 0.125649 +-1.900001 -0.794593 -1.856215 -1.000000 +-1.900001 -1.899676 -2.686929 -1.000000 +-1.900001 -1.900001 -2.699905 -1.000000 +-1.900001 -1.900000 -2.612762 -1.000000 +-1.900001 -1.900000 -2.496666 -1.000000 +-2.710000 -1.900000 -2.547701 -1.000000 +-4.338998 -1.900001 -2.709645 -1.900001 +-inf -3.710000 -5.338910 -4.609924 + +-4.183285 -inf -4.162260 -4.220289 +-3.328482 -3.369124 -3.308642 -3.387987 +-3.384517 -3.237135 -3.186654 -3.547319 +-3.244798 -3.347887 -3.188330 -3.635214 +-3.290867 -3.399524 -3.143678 -3.206496 +-3.178502 -3.229257 -2.669657 -3.258358 +-3.022585 -3.253171 -2.833909 -3.061957 +-3.006798 -3.072304 -2.864305 -3.079703 +-2.620468 -3.187870 -2.489275 -2.748013 +-1.651850 -2.675789 -2.449108 -2.456870 +0.055916 -2.706585 -1.837872 -1.826396 +-0.717618 -0.896898 2.307069 0.261593 +-2.694875 -0.250815 -1.648650 -1.900000 +-2.709962 -1.900003 -1.560216 -1.900000 +-2.709882 -2.709995 -1.691608 -1.900001 +-2.703158 -2.697379 -1.221654 -1.900001 +-2.704512 -2.642308 -1.427349 -1.900001 +-2.706321 -2.695619 -1.500919 -1.900001 +-4.338856 -2.682925 -1.834983 -2.710000 +-inf -3.707497 -4.609908 -5.338998 + +-3.721596 -inf -4.029130 -3.952186 +-2.996535 -3.073560 -2.492139 -3.142934 +-2.909095 -3.000956 -2.228656 -3.283917 +-2.723144 -2.922521 -2.217355 -2.853864 +-2.674579 -2.754719 -2.158281 -3.215363 +-2.666374 -2.812000 -1.457342 -3.157097 +-2.670859 -2.658697 -1.507422 -2.804993 +-2.494610 -2.596176 -1.686997 -2.926475 +-2.391836 -2.602111 -1.277282 -2.707037 +-1.703670 -2.318170 -1.907108 -2.256761 +0.769055 -2.560585 -0.593388 -1.692751 +-0.083216 -0.405476 2.869164 1.262278 +-1.648162 -0.297253 1.120782 -1.865092 +-1.718086 -1.900000 0.753370 -2.709458 +-1.813076 -1.678947 0.408040 -2.695457 +-1.783234 -1.802537 0.349882 -2.571939 +-1.849852 -1.441078 -0.028031 -2.637483 +-1.873048 -1.755820 -0.231561 -2.643139 +-3.609951 -1.834761 -0.685006 -2.706331 +-inf -2.889693 -3.797945 -5.338981 + +-3.398081 -inf -3.354731 -3.739691 +-2.443351 -2.931653 -1.224859 -2.973458 +-2.302281 -2.349213 -0.725486 -2.799380 +-2.101231 -2.392602 -0.389885 -2.665149 +-2.265953 -2.059932 -0.235022 -2.679044 +-1.736058 -2.106987 0.421618 -2.304682 +-2.005055 -1.785582 0.595935 -2.674558 +-1.759819 -1.738128 0.396730 -2.479496 +-1.738897 -1.865793 1.397115 -2.353048 +0.696632 -1.282745 -1.199452 -2.184319 +2.221342 -0.443685 3.756810 -0.173683 +2.014790 3.352883 2.463095 1.976488 +1.785244 2.962442 0.881539 0.263114 +1.627693 2.562740 0.439778 0.130677 +1.189365 2.204250 0.049065 -0.124982 +0.625776 1.834433 -0.101427 -0.142865 +0.511893 1.478959 -0.561052 -0.456538 +0.331346 1.197169 -0.607668 -0.620863 +-1.769361 0.873786 -0.764424 -0.856201 +-inf -1.741657 -4.609486 -4.609950 + +-2.575721 -inf -1.121719 -3.830434 +-1.106661 -2.570340 0.334745 -2.426420 +-0.918217 -1.457190 0.916686 -2.125718 +-1.004224 -0.885310 1.330844 -2.065869 +-0.146443 -0.689678 1.623615 -2.081175 +0.042350 -0.321949 1.923996 -1.383381 +-0.334566 -0.720288 2.339499 -1.589244 +1.165615 -0.561692 2.737690 -1.698326 +0.094683 0.388002 3.134630 -0.321230 +0.396634 -0.652778 3.293358 -1.388187 +2.052101 2.206358 4.199362 2.739755 +0.005432 2.645466 2.768298 1.508389 +-0.798568 1.426578 0.241189 0.018649 +-1.425096 -0.604742 -0.575703 0.890797 +-1.861391 -1.167395 -2.201588 0.523328 +-1.712059 -1.634296 -2.680668 0.232589 +-1.758092 -1.571436 -2.650356 -0.142451 +-1.859180 -1.687546 -2.709281 -0.364806 +-3.593831 -1.846245 -2.701725 -0.516759 +-inf -2.814749 -5.338676 -3.800000 + +1.509213 -inf 0.211279 -1.648810 +2.035505 0.165889 -0.745439 -0.630469 +2.388227 0.838252 -0.288485 0.053361 +2.695955 1.649876 0.708541 0.815902 +3.023451 2.227096 1.146648 1.077552 +3.377063 2.476218 1.180343 1.560209 +3.770103 2.887543 1.837956 1.898522 +4.198673 3.329895 3.301814 2.398077 +4.674651 3.659042 2.692899 2.657773 +5.188022 5.203912 4.144193 3.707884 +3.737526 4.678201 2.807472 3.737651 +2.436544 4.204014 3.357058 2.466344 +-0.686145 2.752549 0.700187 -0.399577 +-2.305789 1.272478 -1.848662 -1.443616 +-2.709959 -0.531206 -3.026709 -1.749823 +-2.691890 -2.330158 -3.438999 -1.655271 +-2.707880 -2.683309 -3.437990 -1.578691 +-2.710000 -2.673462 -3.438136 -1.804987 +-4.338938 -2.706997 -3.438271 -1.762899 +-inf -3.703363 -5.995096 -4.609845 + +-0.957302 -inf -0.222525 0.920623 +-1.601651 -1.333242 -1.833346 -0.103909 +-1.423739 -1.601699 -1.824930 0.553422 +-0.599002 -1.459756 -2.148844 1.223213 +-0.538439 -1.245355 -2.217913 1.600663 +-0.515298 -0.999166 -2.429444 1.782483 +2.314057 -1.065278 -1.261408 1.322062 +2.192054 1.570474 2.736615 3.766953 +0.766749 1.648037 -0.696223 3.137199 +-0.197806 0.778313 -0.787378 3.571318 +1.822024 1.962516 -0.094091 3.175766 +2.014364 2.589218 2.959602 3.776861 +-1.293150 2.349107 0.149852 0.831107 +-3.037539 0.682192 -1.528641 -1.569630 +-3.392824 -1.246923 -3.207945 -2.633946 +-3.420027 -3.209251 -3.980963 -2.694098 +-3.438465 -3.438608 -4.081285 -2.639473 +-3.437399 -3.435231 -4.095001 -2.700676 +-4.995095 -3.438433 -4.095054 -2.686618 +-inf -4.438986 -6.580928 -5.338869 + +-1.132238 -inf -0.278661 0.458560 +-1.850568 -1.074837 -1.872234 -1.816041 +-1.871858 -1.840247 -1.824256 -1.453070 +-2.135311 -1.902728 -2.165005 -1.076294 +-2.177799 -2.127266 -2.015535 -0.946188 +-0.907224 -2.261487 -2.219897 -1.601823 +1.518276 -2.490279 -1.500550 -0.779748 +0.368635 0.133226 2.193211 3.366218 +-1.018504 1.456100 -1.713427 -0.127158 +-1.003823 -1.448153 -2.461837 1.707415 +1.982909 -0.193900 -0.615203 0.469193 +1.693912 1.691306 2.685710 3.390409 +-1.016257 2.012876 0.542161 0.592231 +-2.815756 0.650495 -0.517161 -2.015034 +-3.663712 -1.126038 -2.211071 -2.987425 +-3.795615 -3.039694 -3.392062 -3.403194 +-3.970620 -3.863986 -3.847671 -3.429492 +-3.940268 -4.065506 -4.556812 -3.438825 +-5.557994 -4.060003 -4.661060 -3.438306 +-inf -5.094913 -6.748498 -5.633913 + +-1.015494 -inf -0.000817 -0.040316 +-2.247467 -1.024341 -1.698770 -2.010062 +-2.056077 -1.958284 -2.076730 -2.012950 +-2.317020 -2.150683 -2.258864 -2.104657 +-2.278718 -2.188895 -2.192365 -2.134938 +-1.478381 -2.266169 -2.332889 -2.246461 +0.546917 -2.612055 -1.715395 -1.393737 +0.134608 -0.424833 1.333672 2.985886 +-2.426531 0.947889 -1.528232 -1.254570 +-1.747584 -0.829820 -2.581706 -1.712536 +1.624980 -2.247350 -2.286926 -0.684606 +2.357174 1.276387 1.403750 3.041814 +1.157404 2.726074 2.113332 1.593618 +-1.887382 1.403785 -0.858739 -1.624927 +-3.320011 -0.160386 -2.574795 -2.969099 +-3.900157 -2.229226 -3.361364 -3.844614 +-4.041080 -3.332581 -3.817717 -3.897845 +-4.281750 -4.052223 -4.252500 -4.065700 +-5.512602 -4.462123 -4.791813 -4.094012 +-inf -5.634279 -6.111973 -5.831636 + +-0.901818 -inf -0.000000 -0.008221 +-2.341886 -1.000071 -1.859816 -1.973442 +-2.132497 -1.914293 -1.943504 -2.168207 +-2.293568 -2.283182 -2.357035 -2.290995 +-2.253454 -2.404329 -2.355658 -2.255313 +-1.688611 -2.233243 -2.041470 -2.070862 +0.353255 -2.346967 -1.961852 -1.488788 +-0.631125 -0.525519 0.739731 2.586745 +-2.494800 0.601141 -1.901219 -1.734393 +-2.279230 -1.420592 -2.564224 -2.515826 +-1.203519 -2.672915 -2.626987 -0.166120 +0.624708 -1.872802 -1.325005 1.674540 +0.705154 1.408844 1.851560 2.442546 +-2.272894 1.038756 -1.030684 -0.608385 +-3.410419 -0.604372 -2.470509 -2.500124 +-4.030684 -2.281563 -3.421676 -3.384126 +-4.553441 -3.322217 -3.438972 -4.073059 +-4.741387 -4.090909 -4.091933 -4.382614 +-5.031007 -4.568268 -4.545900 -4.543759 +-inf -5.629125 -5.942983 -6.006789 + +-0.900001 -inf -0.000000 -0.000000 +-2.705200 -1.000000 -1.899556 -1.903722 +-2.730727 -1.899888 -2.488106 -2.281820 +-2.410406 -2.398748 -2.463934 -2.368081 +-2.308624 -2.280937 -2.321168 -2.403951 +-1.804373 -2.195328 -2.190666 -2.051587 +-0.092321 -2.433987 -1.893678 -1.845178 +-0.811666 -0.881466 0.111465 1.986492 +-2.341100 -0.408926 -1.788938 -1.667889 +-2.239699 -1.890851 -2.201438 -2.239548 +-0.921335 -2.634221 -2.596022 -2.457925 +0.878172 -2.424428 -0.908781 -0.614720 +0.641596 0.630388 1.644767 2.181597 +-2.649989 0.906960 -1.324415 -1.140068 +-3.437313 -1.183866 -2.709746 -2.303409 +-3.438745 -2.710000 -2.695814 -3.388588 +-4.095096 -3.438998 -2.700996 -4.095031 +-4.680108 -3.438998 -3.438998 -4.676852 +-5.889963 -4.094959 -4.094975 -4.687017 +-inf -5.654156 -6.070887 -6.088222 + +-0.900001 -inf -0.000000 -0.000000 +-2.710002 -1.000000 -1.900001 -1.900001 +-2.708929 -1.900001 -1.919693 -2.660393 +-2.433759 -2.361001 -1.923721 -2.414618 +-2.202663 -2.295594 -1.945012 -2.200115 +-1.854514 -2.266992 -1.932779 -2.071572 +-0.784607 -2.401839 -1.852893 -1.773518 +-0.918816 -0.943957 0.057257 0.869875 +-1.954500 -0.849698 -1.823554 -1.886462 +-2.424364 -1.916788 -1.813995 -2.355534 +-1.206935 -2.659285 -1.772889 -2.588791 +0.696544 -2.458062 -1.119762 -0.889271 +0.416501 0.510874 1.442793 1.950166 +-2.446561 0.665948 -1.263155 -1.071141 +-2.700044 -0.931978 -1.886507 -2.666502 +-2.708763 -2.664064 -1.789394 -3.436230 +-3.438821 -2.705108 -1.833923 -3.438343 +-4.095096 -2.703003 -2.707657 -4.095096 +-5.585411 -3.438698 -3.438999 -4.684779 +-inf -5.095076 -5.962158 -6.672168 + +-0.900001 -inf -0.000000 -0.000000 +-1.900003 -1.000000 -1.000003 -1.900001 +-1.950877 -1.900674 -1.000001 -2.664263 +-1.888274 -1.794510 -1.002111 -2.558401 +-1.699556 -1.854968 -1.015470 -2.161805 +-1.789701 -1.915670 -1.008219 -2.462382 +-0.940472 -2.021644 -1.154321 -1.918295 +-0.886537 -0.932827 0.253190 0.038897 +-1.766414 -1.061828 -0.768689 -1.874604 +-1.843923 -1.889836 -0.443630 -2.666189 +-1.698554 -1.876585 -0.060049 -2.675165 +0.484832 -1.617560 -0.255220 -1.047485 +0.109920 0.298847 1.279096 1.743023 +-1.748201 0.411371 -0.540462 -1.074895 +-1.852824 -1.671469 -0.366127 -2.445540 +-1.886475 -1.875651 -0.448161 -2.690770 +-2.709841 -1.821923 -0.677823 -2.709760 +-3.438999 -1.842234 -2.799587 -3.438998 +-4.995096 -2.706095 -4.419141 -4.095096 +-inf -4.438953 -6.877721 -6.581941 + +-0.000000 -inf -0.000000 -0.000000 +-0.000083 -0.000000 -0.900300 -0.900018 +-0.008969 -0.000000 -0.905180 -0.901356 +-0.271961 -0.000019 -1.014280 -0.970785 +0.082751 -0.436158 -1.012202 -1.040589 +0.251577 -0.079704 -0.991274 -0.997974 +0.417352 0.035992 -1.031573 -0.912512 +0.669976 0.036491 -1.765555 0.014481 +0.869275 0.283700 -0.820517 -0.878145 +1.047198 0.446700 -0.624459 -0.746547 +1.212757 0.633014 -0.346242 -0.389771 +1.376224 0.813355 -0.349317 0.022151 +1.087382 1.131760 0.030389 1.553730 +0.442751 1.367623 -0.168104 -0.150912 +0.448789 1.181694 -0.553553 -0.599639 +0.129305 1.006072 -0.727960 -0.735712 +-1.795992 0.704386 -0.871518 -0.867968 +-5.419961 -1.869812 -3.708857 -3.709809 +-6.877996 -3.784166 -4.438998 -4.438998 +-inf -5.419710 -5.995081 -5.995090 + +-0.903302 -inf -1.794359 -0.000000 +-1.888512 -1.081474 -1.370784 -1.000025 +-1.894270 -1.809297 -1.319707 -1.000535 +-1.790949 -1.799560 -1.333036 -1.022939 +-1.809634 -1.918411 -1.364628 -1.001793 +-1.772265 -1.904872 -1.368757 -0.990979 +-2.318136 -1.869989 -2.433337 -0.878539 +-2.769711 -2.806413 -3.794161 -1.789015 +-1.771598 -2.738337 -3.300342 -0.669164 +-1.601502 -1.892425 -3.455499 -0.320804 +-1.571903 -1.642375 -3.570842 -0.093219 +-1.526182 -1.731464 -3.605724 -0.020657 +-1.630193 -1.752972 -3.367834 0.255624 +-1.660233 -1.588302 -3.606789 0.082369 +-1.767865 -1.675711 -3.609663 -0.179861 +-1.896875 -1.709686 -3.602725 -0.412042 +-2.709350 -1.795107 -3.609460 -0.825490 +-3.438999 -1.855386 -4.338983 -2.799587 +-4.995089 -2.705861 -4.995088 -4.419998 +-inf -4.438801 -7.395193 -6.877779 + +-2.274823 -inf -inf -1.998917 +-0.239060 -1.361621 -inf -1.030196 +-0.192977 -0.623675 -inf -1.015081 +-0.178113 -0.338083 -inf -1.033181 +-0.169390 -0.233137 -inf -1.011519 +-2.047086 -0.170447 -inf -0.964664 +-3.698861 -2.238323 -inf -2.828518 +-3.362710 -3.328363 -inf -3.314670 +-3.838189 -3.435092 -inf -2.860093 +-3.981106 -3.859570 -inf -2.725594 +-4.481407 -4.360524 -inf -2.635113 +-4.568501 -4.598739 -inf -2.773824 +-4.557566 -4.603247 -inf -2.345359 +-4.605671 -4.609997 -inf -2.615880 +-4.609488 -4.600443 -inf -2.757381 +-4.609990 -4.609360 -inf -2.785457 +-5.338998 -4.598870 -inf -2.894095 +-5.995094 -4.609997 -inf -3.707547 +-7.395545 -5.338997 -inf -4.438797 +-inf -5.995087 -inf -5.995077 + diff --git a/travail_de_groupe/jeu_appren_par_renfo/moving_ball/src/main.c b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/src/main.c new file mode 100644 index 0000000000000000000000000000000000000000..abb6e7eec6e81a1d2530a2c62860dacd29af37c1 --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/moving_ball/src/main.c @@ -0,0 +1,396 @@ +#include <stdio.h> +#include <stdlib.h> +#include <SDL2/SDL.h> +#include <SDL2/SDL_image.h> +#include <SDL2/SDL_ttf.h> +#include <math.h> +#include <time.h> +#define M_PI 3.14159265358979323846 +#define MAPSIZE 20 + +int running = 1; + + +void readMapFromFile(char * filename, int map[][MAPSIZE]){ + FILE * fp; + fp = fopen(filename, "r"); + if(fp == NULL){ + printf("Error opening file\n"); + exit(1); + } + int i, j; + for(i = 0; i < MAPSIZE; i++){ + for(j = 0; j < MAPSIZE; j++){ + fscanf(fp, "%d", &map[i][j]); + } + } + fclose(fp); +} + +typedef struct Ball { + int x; + int y; + int radius; + int weight; + int isGrounded; +} Ball_t; + +void printMap(int map[][MAPSIZE]){ + int i, j; + for(i = 0; i < MAPSIZE; i++){ + for(j = 0; j < MAPSIZE; j++){ + printf("%d ", map[i][j]); + } + printf("\n"); + } +} + +#define GRAVITY 1 + +int hitAngle; +int hitIntensity; + +void moveBall(Ball_t * ball, int choice){ + switch (choice) + { + case 0: + ball->x += 1; + break; + + case 1: + ball->x -= 1; + break; + + case 2: + ball->y += 1; + break; + + case 3: + ball->y -= 1; + break; + } +} + +void drawMap(SDL_Renderer * renderer, int map[][MAPSIZE], Ball_t * ball){ + int i, j; + for(i = 0; i < MAPSIZE; i++){ + for(j = 0; j < MAPSIZE; j++){ + if (i == ball->y && j == ball->x){ + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderDrawPoint(renderer, j, i); + } + else if (map[i][j] == 1){ + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_RenderDrawPoint(renderer, j, i); + } + else if (map[i][j] == 2){ + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderDrawPoint(renderer, j, i); + } + } + } +} + +float *** allocateAndInitiateQ(){ + float *** q = malloc(sizeof(int **) * MAPSIZE); + int i, j, k; + for(i = 0; i < MAPSIZE; i++){ + q[i] = malloc(sizeof(float *) * MAPSIZE); + for(j = 0; j < MAPSIZE; j++){ + q[i][j] = malloc(sizeof(float) * 4); + + if (i > 0 && i < MAPSIZE - 1 && j > 0 && j < MAPSIZE - 1){ + for(k = 0; k < 4; k++){ + q[i][j][k] = -1; + } + } + else if (i == 0 && j == 0){ + int kPossibleValues[2] = {0, 2}; + for(k = 0; k < 2; k++){ + q[i][j][kPossibleValues[k]] = -1; + } + q[i][j][3] = -INFINITY; + q[i][j][1] = -INFINITY; + } + else if (i == 0 && j == MAPSIZE - 1){ + int kPossibleValues[2] = {1, 2}; + for(k = 0; k < 2; k++){ + q[i][j][kPossibleValues[k]] = -1; + } + q[i][j][0] = -INFINITY; + q[i][j][3] = -INFINITY; + } + else if (i == MAPSIZE - 1 && j == 0){ + int kPossibleValues[2] = {0, 3}; + for(k = 0; k < 2; k++){ + q[i][j][kPossibleValues[k]] = -1; + } + q[i][j][1] = -INFINITY; + q[i][j][2] = -INFINITY; + } + else if (i == MAPSIZE - 1 && j == MAPSIZE - 1){ + int kPossibleValues[2] = {1, 3}; + for(k = 0; k < 2; k++){ + q[i][j][kPossibleValues[k]] = -1; + } + q[i][j][0] = -INFINITY; + q[i][j][2] = -INFINITY; + } + else if (j == MAPSIZE - 1){ + int kPossibleValues[3] = {1, 2, 3}; + for(k = 0; k < 3 ;k++){ + q[i][j][kPossibleValues[k]] = -1; + } + q[i][j][0] = -INFINITY; + } + else if (i == MAPSIZE - 1){ + int kPossibleValues[3] = {0, 1, 3}; + for(k = 0; k < 3; k++){ + q[i][j][kPossibleValues[k]] = -1; + } + q[i][j][2] = -INFINITY; + } + else if (j == 0){ + int kPossibleValues[3] = {0, 2, 3}; + for(k = 0; k < 3; k++){ + q[i][j][kPossibleValues[k]] = -1; + } + q[i][j][1] = -INFINITY; + } + else if (i == 0){ + int kPossibleValues[3] = {0, 1, 2}; + for(k = 0; k < 3; k++){ + q[i][j][kPossibleValues[k]] = -1; + } + q[i][j][3] = -INFINITY; + } + } + } + return q; +} + +int argmax(float * arr, int size){ + int i; + float max = arr[0]; + int maxIndex = 0; + printf("argmax: %f ", arr[0]); + for(i = 1; i < size; i++){ + printf("%f ", arr[i]); + if (arr[i] > max){ + max = arr[i]; + maxIndex = i; + } + } + printf("\n"); + return maxIndex; +} + +int take_action(Ball_t * ball, float *** Q, float eps){ + int action; + int proba = rand() % 100; + if (proba < eps * 100){ + if (ball->x > 0 && ball->x < MAPSIZE - 1 && ball->y > 0 && ball->y < MAPSIZE - 1){ + action = rand() % 4; + } + else if (ball->x == 0 && ball->y > 0 && ball->y < MAPSIZE - 1){ + int possibleActions[3] = {0, 3, 2}; + action = possibleActions[rand() % 3]; + } + else if (ball->x == MAPSIZE - 1 && ball->y > 0 && ball->y < MAPSIZE - 1){ + int possibleActions[3] = {1, 3, 2}; + action = possibleActions[rand() % 3]; + } + else if (ball->y == 0 && ball->x > 0 && ball->x < MAPSIZE - 1){ + int possibleActions[3] = {0, 1, 2}; + action = possibleActions[rand() % 3]; + } + else if (ball->y == MAPSIZE - 1 && ball->x > 0 && ball->x < MAPSIZE - 1){ + int possibleActions[3] = {0, 1, 3}; + action = possibleActions[rand() % 3]; + } + else if (ball->x == 0 && ball->y == 0){ + int possibleActions[2] = {0, 2}; + action = possibleActions[rand() % 2]; + } + else if (ball->x == 0 && ball->y == MAPSIZE - 1){ + int possibleActions[2] = {0, 3}; + action = possibleActions[rand() % 2]; + } + else if (ball->x == MAPSIZE - 1 && ball->y == 0){ + int possibleActions[2] = {1, 2}; + action = possibleActions[rand() % 2]; + } + else if (ball->x == MAPSIZE - 1 && ball->y == MAPSIZE - 1){ + int possibleActions[2] = {1, 3}; + action = possibleActions[rand() % 2]; + } + else{ + action = rand() % 4; + } + } + else{ + action = argmax(Q[ball->y][ball->x],4); + //printf("wtf"); + } + return action; +} + +int setReward(Ball_t * ball, int map[][MAPSIZE]){ + if (map[ball->y][ball->x] == 1){ + return 0; + } + else if (map[ball->y][ball->x] == 2){ + return 1; + } + else if (map[ball->y][ball->x] == 3){ + return -2; + } + else{ + return -1; + } +} + +void printQ(float *** Q){ + int i, j, k; + for(i = 0; i < MAPSIZE; i++){ + for(j = 0; j < MAPSIZE; j++){ + printf("Q for %d %d: ", i, j); + for(k = 0; k < 4; k++){ + printf("%f ", Q[i][j][k]); + } + printf("\n"); + } + printf("\n"); + } +} + +void writeQ(float *** Q){ + int i, j, k; + FILE * fp = fopen("q.txt", "w+"); + for(i = 0; i < MAPSIZE; i++){ + for(j = 0; j < MAPSIZE; j++){ + for(k = 0; k < 4; k++){ + fprintf(fp, "%f ", Q[i][j][k]); + } + fprintf(fp, "\n"); + } + fprintf(fp, "\n"); + } + fflush(fp); + fclose(fp); +} + +typedef struct path_t{ + int x; + int y; + struct path_t * next; +} path_t; + +// chain list to track the path taken + +void insertPointToPath(path_t ** head, int x, int y){ + path_t * newPoint = (path_t *)malloc(sizeof(path_t)); + newPoint->x = x; + newPoint->y = y; + newPoint->next = *head; + *head = newPoint; +} + +int checkIfPointInPath(path_t * head, int x, int y){ + path_t * current = head; + while(current != NULL){ + if (current->x == x && current->y == y){ + return 1; + } + current = current->next; + } + return 0; +} + +void freePath(path_t * head){ + path_t * current = head; + while(current != NULL){ + path_t * temp = current; + current = current->next; + free(temp); + } +} + +int main(){ + Ball_t ball; + ball.weight = 100; + ball.isGrounded = 1; + + path_t * path = NULL; + path = (path_t *)malloc(sizeof(path_t)); + + srand(time(NULL)); + + int map[MAPSIZE][MAPSIZE]; + readMapFromFile("map.txt", map); + //printMap(map); + + float *** Q = allocateAndInitiateQ(); + + for (int i = 0; i < 1000; i++){ + freePath(path); + path = (path_t *)malloc(sizeof(path_t)); + ball.x = rand() % MAPSIZE; + ball.y = rand() % MAPSIZE; + while (running){ + if (map[ball.y][ball.x] == 2){ + printf("%d : found at %d %d\n", i, ball.x, ball.y); + running = 0; + } + + int action = take_action(&ball, Q, 0.5); + printf("[%d] Action: %d\n", i, action); + int reward = setReward(&ball, map); + + printf("[%d] Reward: %d\n", i, reward); + + printf("Ball: %d %d\n", ball.x, ball.y); + fflush(stdout); + + Ball_t * nextBall = malloc(sizeof(Ball_t)); + nextBall->x = ball.x; + nextBall->y = ball.y; + nextBall->weight = ball.weight; + nextBall->isGrounded = ball.isGrounded; + moveBall(nextBall, action); + + printf("Next Ball: %d, %d\n", nextBall->x, nextBall->y); + + int nextAction = argmax(Q[nextBall->y][nextBall->x],4); + + + Q[ball.y][ball.x][action] = Q[ball.y][ball.x][action] + 0.1 * (reward + 0.9 * Q[nextBall->y][nextBall->x][nextAction] - Q[ball.y][ball.x][action]); + printf("Q: %f\n", Q[ball.y][ball.x][action] + 0.1 * (reward + 0.9 * Q[nextBall->y][nextBall->x][nextAction] - Q[ball.y][ball.x][action])); + + moveBall(&ball, action); + } + running = 1; + } + //printQ(Q); + writeQ(Q); + + // use Q after training + ball.x = rand() % MAPSIZE; + ball.y = rand() % MAPSIZE; + // use Q + + while (running){ + if (map[ball.y][ball.x] == 2){ + printf("found at final %d %d\n", ball.x, ball.y); + running = 0; + } + int action = take_action(&ball, Q, 0.1); + printf("Action: %d\n", action); + int reward = setReward(&ball, map); + printf("Reward: %d\n", reward); + + moveBall(&ball, action); + printf("Ball: %d %d\n", ball.x, ball.y); + fflush(stdout); + } +} \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c b/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c index d57aab50b03e5c9634d50d5ce73e9cf84fc87b70..3dd0fb5f43a973a865a04962a032f233a35d1acc 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/gest_event.c @@ -34,7 +34,11 @@ void *EventLoop(void *arg){ while(running){ switch(game_state){ case MENU : gestMenu();break; +<<<<<<< HEAD //case GAME : gestGame();break; +======= + case GAME : gestMenu();break; +>>>>>>> main default:printf("game state fault");break; } } diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/main.c b/travail_de_groupe/jeu_appren_par_renfo/src/main.c index f75b6386f524623f953f62d44fa395839234014c..623aa91b2afa3bd546a5ee43cb97cea99ce2ec07 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/main.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/main.c @@ -6,8 +6,16 @@ int game_state; int main(){ running = 1; +<<<<<<< HEAD game_state = MENU; MainLoop(); +======= + game_state = GAME; + readMapFromFile("map.txt"); + printMap(); + + mainLoop(); +>>>>>>> main } \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/main.h b/travail_de_groupe/jeu_appren_par_renfo/src/main.h index eb08e389951121f3d8efafe7a7b22f11dae367fe..a39be0d132dfd51b273762cfeed9e54fe72a8b5c 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/main.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/main.h @@ -16,6 +16,10 @@ #include "render.h" #include "gest_event.h" +<<<<<<< HEAD +======= +#include "map.h" +>>>>>>> main #define MENU 0 diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/map.c b/travail_de_groupe/jeu_appren_par_renfo/src/map.c new file mode 100644 index 0000000000000000000000000000000000000000..97e1d63b3ea8ff94e670af0deee711c18007500b --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/src/map.c @@ -0,0 +1,30 @@ +#include "map.h" + +int map[MAP_HEIGHT][MAP_WIDTH]; + + +void readMapFromFile(char *file_name){ + FILE *file = fopen(file_name, "r"); + if (file == NULL){ + printf("Couldn't open map file."); + exit(EXIT_FAILURE); + } + int i, j; + for (i = 0; i < MAP_HEIGHT ; i++){ + for (j = 0; j < MAP_WIDTH; j++){ + fscanf(file, "%d", &map[i][j]); + } + } + fclose(file); +} + + +void printMap(){ + int i, j; + for (i = 0; i < MAP_HEIGHT; i++){ + for (j = 0; j < MAP_WIDTH; j++){ + printf("%d ", map[i][j]); + } + printf("\n"); + } +} \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/map.h b/travail_de_groupe/jeu_appren_par_renfo/src/map.h new file mode 100644 index 0000000000000000000000000000000000000000..0ba0db56a73b8c5e2dd6500593b1549f72609cca --- /dev/null +++ b/travail_de_groupe/jeu_appren_par_renfo/src/map.h @@ -0,0 +1,16 @@ +#ifndef MAP_HEADER_ +#define MAP_HEADER_ + +#include "main.h" + + +#define MAP_WIDTH 31 +#define MAP_HEIGHT 17 + + +extern int map[MAP_HEIGHT][MAP_WIDTH]; + +void readMapFromFile(char *file_name); +void printMap(); + +#endif \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/render.c b/travail_de_groupe/jeu_appren_par_renfo/src/render.c index b0f7d94e2fee0692bb61ab8895cbf41e3a4b51b4..91e541e8a4f3a96d0e4125617933af9e3dd048b4 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.c @@ -4,18 +4,42 @@ SDL_Window *window; SDL_Renderer *renderer; TTF_Font *RobotoFont; +<<<<<<< HEAD void CreateWindow(){ SDL_DisplayMode ScreenDimension; +======= +SDL_DisplayMode screenDimension; + +SDL_Rect rect; +SDL_Rect sky; +SDL_Rect ground; + +// ray casting variables +float htexture; +int r, mx, my, dof; +double rx, ry, xo, yo, distT; +double ra = player->angle - DR * FOV_ANGLE/4; + +// end ray casting variables + +void createWindow(){ +>>>>>>> main if (SDL_Init(SDL_INIT_VIDEO) != 0){ printf("Couldn't create window."); exit(EXIT_FAILURE); } +<<<<<<< HEAD SDL_GetCurrentDisplayMode(0, &ScreenDimension); window = SDL_CreateWindow("Game Of Life", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, ScreenDimension.w, ScreenDimension.h, SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP); +======= + SDL_GetCurrentDisplayMode(0, &screenDimension); + + window = SDL_CreateWindow("Mat Le King", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenDimension.w, screenDimension.h, SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP); +>>>>>>> main if (window == NULL){ printf("Couldn't create window"); @@ -38,9 +62,159 @@ void CreateWindow(){ } +void endSDL(){ + SDL_DestroyWindow(window); + SDL_DestroyRenderer(renderer); + TTF_CloseFont(RobotoFont); + TTF_Quit(); + SDL_Quit(); +} -void MainLoop(){ - CreateWindow(); +void drawRays(int map[][MAP_WIDTH]){ + if (ra < 0) ra -= 2*pi; + if (ra > 2*pi) ra -= 2*pi; + for (r = 0; r<NB_RAYS; r++){ + // check horizontal rays + dof = 0; + float disH = 100000, hx = player->x, hy = player->y; + float aTan = -1/tan(ra); + if (ra > pi){ // looking up + ry = (((int)player->y>>6)<<6) - 0.0001; + rx = (player->y - ry) * aTan + player->x; + yo = -BLOCK_SIZE; + xo = -yo*aTan; + } + if (ra<pi){ // looking down + ry = (((int)player->y>>6)<<6) + BLOCK_SIZE; + rx = (player->y - ry) * aTan + player->x; + yo = BLOCK_SIZE; + xo = -yo*aTan; + } + if (ra == pi){ + ry = player->y; + rx = player->x; + dof = DOF; + } + while (dof < DOF){ + mx = (int)rx>>6; + my = (int)ry>>6; + if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT){ + if (map[my][mx] == 1){ + hx = rx; + hy = ry; + disH = sqrt((rx-player->x)*(rx-player->x) + (ry-player->y)*(ry-player->y)); + dof = DOF; + } + } + else { + rx += xo; + ry += yo; + dof++; + } + } + + // check vertical rays + dof = 0; + float disV = 100000, vx = player->x, vy = player->y; + float nTan = -tan(ra); + if (ra > pi/2 && ra < 3*pi/2){ // looking left + rx = (((int)player->x>>6)<<6) - 0.0001; + ry = player->y + (player->x - rx) * nTan; + xo = -BLOCK_SIZE; + yo = -xo*nTan; + } + if (ra<pi/2 || ra > 3*pi/2){ // looking right + rx = (((int)player->x>>6)<<6) + BLOCK_SIZE; + ry = player->y + (player->x - rx) * nTan; + xo = BLOCK_SIZE; + yo = -xo*nTan; + } + while (dof < DOF){ + mx = (int)rx>>6; + my = (int)ry>>6; + if (mx >= 0 && mx < MAP_WIDTH && my >= 0 && my < MAP_HEIGHT){ + if (map[my][mx] == 1){ + vx = rx; + vy = ry; + disV = sqrt((rx-player->x)*(rx-player->x) + (ry-player->y)*(ry-player->y)); + dof = DOF; + } + } + else { + rx += xo; + ry += yo; + dof++; + } + } + if (disH < disV) { + rx = hx; + ry = hy; + distT = disH; + } + else { + rx = vx; + ry = vy; + distT = disV; + } + ra = ra + ANGLE_INC/2; + if (ra > 2*pi) ra -= 2*pi; + if (ra < 0) ra += 2*pi; + + // draw column + float ca = player->angle - ra; + if (ca < 0) ca += 2*pi; + if (ca > 2*pi) ca -= 2*pi; + distT = distT * cos(ca); + float lineH = (screenDimension.h/2)/distT; + + rect.x = r; + rect.y = lineH; + rect.w = 1; + rect.h = lineH; + + if (disH < disV) { + SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); + } + else { + SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); + } + SDL_RenderFillRect(renderer, &rect); + } +} + +void drawMap2D(int map[][MAP_WIDTH]){ + int i, j; + rect.w = CELL_SIZE; + rect.h = CELL_SIZE; + rect.x = 0; + rect.y = 0; + for (i = 0; i < MAP_HEIGHT; i++){ + for (j = 0; j < MAP_WIDTH; j++){ + if (map[i][j] == 1){ + SDL_SetRenderDrawColor(renderer, 5, 255, 255, 255); + SDL_RenderFillRect(renderer, &rect); + } + else { + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderFillRect(renderer, &rect); + } + rect.x += CELL_SIZE; + } + rect.y += CELL_SIZE; + rect.x = 0; + } +} + +void drawGame(){ + SDL_RenderClear(renderer); + drawMap2D(map); + SDL_RenderPresent(renderer); +} + + + +void mainLoop(){ + createWindow(); unsigned int a = SDL_GetTicks(); unsigned int b = SDL_GetTicks(); @@ -54,22 +228,24 @@ void MainLoop(){ while (running){ a = SDL_GetTicks(); - delta = (a - b) / 1000.0; - if (delta > 1/FPS_TO_GET){ + delta = (a - b); + if (delta > 1000/FPS_TO_GET){ + //printf("fps: %f\n", 1000/delta); b = a; switch (game_state){ case MENU: //Menu(); break; case GAME: - //Game(); + drawGame(); break; } } else { // fait dormir le thread pour garder des ressources - usleep(1000 * (1/FPS_TO_GET - delta)); + usleep(1000 * (1000/FPS_TO_GET - delta)); } - } + + endSDL(); } \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/src/render.h b/travail_de_groupe/jeu_appren_par_renfo/src/render.h index 75f94e37b205ac0527e22d0a41fdef98e84dc682..507711d2aff55c248d6ecc7b8080c2661ad37236 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/src/render.h +++ b/travail_de_groupe/jeu_appren_par_renfo/src/render.h @@ -3,13 +3,32 @@ #include "main.h" #include "gest_event.h" +<<<<<<< HEAD #define FPS_TO_GET 60 +======= +#include "map.h" + +#define FPS_TO_GET 60 +#define CELL_SIZE 10 + +#define DOF 8 +#define BLOCK_SIZE 64 +#define DR 0.0174533 +#define FOV_ANGLE 60 +#define pi 3.14159265358979323846 +#define NB_RAYS (screenDimension.x) +#define ANGLE_INC ((DR * FOV_ANGLE) / NB_RAYS) +>>>>>>> main extern SDL_Window *window; extern SDL_Renderer *renderer; +<<<<<<< HEAD void MainLoop(); +======= +void mainLoop(); +>>>>>>> main #endif \ No newline at end of file