Skip to content
Snippets Groups Projects
Commit 4529b853 authored by antoinemeyer5's avatar antoinemeyer5
Browse files

travail antoine

parent 9a386fb8
No related branches found
No related tags found
No related merge requests found
Showing
with 543 additions and 0 deletions
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/SDL2"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
\ No newline at end of file
,meyer,pc-meyer,23.06.2022 23:09,file:///home/meyer/.config/libreoffice/4;
\ No newline at end of file
No preview for this file type
Projet ZZ1
Apprentissage par renforcement
Groupe : 5
Membres : Taha Belkhiri, Marc Beret et Antoine Meyer
Définition apprentissage par renforcement :
Programme/agent/système qui réalise une suite d'actions et après un certain laps de temps, qui évalue la qualité de l'état atteint. On remonte alors dans la liste des actions réalisées et on augmente(si éval. finale favorable) leur probabilité de réalisation ou on la diminue (défavorable).
But :
Apprendre à un programme à prendre des décisions.
Besoins :
- un environnement
- des actions/perceptions dans cet environnement
- un agent
Problèmes :
- nombre de simulations très important
- réglage de ξ est laborieux et assez dépendant du problème
Suites décroissantes de limite nulle :
Choix parmis 3 suites.
[4.2.2 La formule de mise à jour]
Formule de mise à jour avec forme de suite : Un+1 = Un + ξ × (a−Un) avec 0<ξ<1
Etendu du résultat à une suite de réalisations d'une variable aléatoire :
- suite de variables aléatoires (An), identiquement distribuées en fonction de n et admettant une même espérance A,
- suite de variables aléatoires (Un) par Un+1 = Un + ξ × (An−Un),
- suite des espérances des variables Un par Vn = E(Un).
Choix de ξ :
- ξ petit (proche de 0) => fluctuations de faible amplitude
- ξ grand (proche de 1) => convergence rapide
- => trouver un compromis et expliquer notre choix !
[4.3 Apprentissage par renforcement]
Mécanisme :Z
1 - regarder le monde
2 - choisir une action
3 - percevoir une récompense
4 - faire un retour d'expérience pour améliorer les choix
[4.4 Qualité d'une action ou d'un état]
IDEES :
- jeu de société
- un jeu avec un petit plateau, un personnage entre, tue un monstre, recupere une cle et sort du plateau. Là le jeu recommence mais le monstre a apprit comment il s'est fait tué. Donc au 2eme tour, il va tenter d'autres moves pour mieux survivre. Tuer le monstre devient donc de + en + compliqué surtout si le joueur si prend de la même manière.
- jeu tower defense où l'algorithme doit défendre des monstres lancés par le joueur.
- une fée soigne et assiste un héro. Elle lui donne de la vie, du mana avec un apprentissage pour être le meilleur soutien possible.
- village avec des pnjs dedans.
- pnj1_pablo : protege la fontaine
- pnj1_
- joueur : clic sur la fontaine , elle perd 3 HP
- il y a un hero il a de la vie, de l'argent, de la mana, de l'attaque, de la défense. Il y a un marchand avec des potions, des épées, etc. Et c'est le marchand, connaissant les stats du héro, qui lui donne un item au hasard qui correspond le mieux a la situation du hero.
File added
travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/assets/background_mat.png

1.05 MiB

File added
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 source/*.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
#include "ball.h"
ball_t ball;
void initBall(){
}
\ No newline at end of file
#ifndef BALL_H
#define BALL_H
typedef struct ball{
int x;
int y;
} ball_t;
extern ball_t ball;
void initBall();
#endif
\ No newline at end of file
#include "canon.h"
canon_t canon;
void initCanon(){
canon.width = 20;
canon.height = 10;
canon.length = 20;
canon.x = 100;
canon.y = 20;
}
\ No newline at end of file
#ifndef CANON_H
#define CANON_H
typedef struct canon{
int x;
int y;
int width;
int height;
int length;
} canon_t;
extern canon_t canon;
void initCanon();
#endif
\ No newline at end of file
#include "gest_event.h"
SDL_Point mousePosition;
void manageGame(){
SDL_Event event;
while (SDL_PollEvent(&event)){
switch(event.type)
{
case SDL_QUIT:
running = 0;
break;
case SDL_KEYUP:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
running = 0;
continue;
default:
continue;
}
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
running = 0;
continue;
case SDLK_e:
initPointDeChute();
break;
case SDLK_r:
newCanon();
break;
default:
continue;
}
break;
case SDL_MOUSEMOTION:
continue;
case SDL_MOUSEBUTTONDOWN:
//
break;
default:
continue;
}
}
SDL_Delay(5);
}
void *eventLoop(void *arg){
while(running){
manageGame();
}
return NULL;
}
\ No newline at end of file
#ifndef _GEST_EVENT_H_
#define _GEST_EVENT_H_
#include "main.h"
#include "render.h"
void manageGame();
void *eventLoop(void *);
#endif
\ No newline at end of file
#include "main.h"
int running;
int main(){
running = 1;
mainLoop();
}
\ No newline at end of file
#ifndef _MAIN_HEADER_
#define _MAIN_HEADER_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <pthread.h>
#include "render.h"
extern int running;
int main();
#endif
\ No newline at end of file
#include "render.h"
SDL_Window *window;
SDL_Renderer *renderer;
int window_width = 900;
int window_height = 700;
TTF_Font *robotoFont;
int zoom = 40;
SDL_Rect terrain;
SDL_Rect filet;
SDL_Rect canon_rect;
SDL_Rect point_de_chute;
int point_x_rand;
int point_y_rand;
void createWindow(){
if (SDL_Init(SDL_INIT_VIDEO) != 0){
printf("Couldn't create window.");
exit(EXIT_FAILURE);
}
window = SDL_CreateWindow("Badminton learning", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_RESIZABLE);
if (window == NULL){
printf("Couldn't create window");
exit(EXIT_FAILURE);
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_PRESENTVSYNC);
if (renderer == NULL){
printf("Couldn't create renderer.");
exit(EXIT_FAILURE);
}
if (TTF_Init() == -1)
{
exit(EXIT_FAILURE);
}
robotoFont = TTF_OpenFont("assets/Roboto-Black.ttf", 50);
}
void endSDL(){
TTF_CloseFont(robotoFont);
TTF_Quit();
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
}
void initTerrain(){
terrain.x = 50;
terrain.y = 50;
terrain.h = 13.40 * zoom;
terrain.w = 5.20 * zoom;
}
void initPointDeChute(){
initTerrain();
srand(time(NULL));
point_x_rand = (int)rand()%terrain.w;
point_y_rand = (int)rand()%(terrain.h/2);
}
void newCanon(){
initTerrain();
srand(time(NULL));
canon.x = (int)rand()%terrain.w;
canon.y = (int)rand()%(terrain.h/2);
}
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, w, h};
SDL_RenderCopy(renderer, texture, NULL, &rect);
SDL_FreeSurface(surface);
SDL_DestroyTexture(texture);
}
void drawTerrainTopView(){
//terrain
initTerrain();
//filet
filet.x = terrain.x;
filet.h = 4;
filet.y = terrain.y + terrain.h/2 - filet.h/2;
filet.w = terrain.w;
//terrain en blanc
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderFillRect(renderer, &terrain);
//filet en vert
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderFillRect(renderer, &filet);
//decoupage des zones
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
//verticale zone haut
SDL_RenderDrawLine(renderer, terrain.x+terrain.w/2, terrain.y, terrain.x+terrain.w/2, terrain.y+terrain.h/2);
//horizontale zone haut
SDL_RenderDrawLine(renderer, terrain.x, terrain.y+terrain.h/4, terrain.x+terrain.w, terrain.y+terrain.h/4);
//verticale bas
SDL_RenderDrawLine(renderer, terrain.x+terrain.w/2, terrain.y+terrain.h/2, terrain.x+terrain.w/2, terrain.y+terrain.h);
//horizontale bas
SDL_RenderDrawLine(renderer, terrain.x, terrain.y+(3*terrain.h)/4, terrain.x+terrain.w, terrain.y+(3*terrain.h)/4);
}
void drawTerrainSideView(){
//terrain
terrain.x = terrain.x + terrain.w + 50;
terrain.y = terrain.y + terrain.h;
terrain.h = 4;
terrain.w = 13.40 * zoom;
//filet
filet.w = 4;
filet.x = terrain.x + terrain.w/2 - filet.w/2;
filet.h = -1.55 * zoom;
filet.y = terrain.y;
//terrain en blanc
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderFillRect(renderer, &terrain);
//filet en vert
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderFillRect(renderer, &filet);
}
void drawCanonTopView(){
//canon
canon_rect.w = canon.width;
canon_rect.h = canon.length;
canon_rect.x = terrain.x + canon.x;
canon_rect.y = terrain.y + canon.y;
//canon en noir
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &canon_rect);
}
void drawPointDeChuteTopView(){
//point de chute de la balle
point_de_chute.w = 5;
point_de_chute.h = 5;
point_de_chute.x = (int)terrain.x + point_x_rand;
point_de_chute.y = (int)terrain.y + terrain.h/2 + point_y_rand;
//point de chute de la balle
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderFillRect(renderer, &point_de_chute);
}
void drawCanonSideView(){
//canon
canon_rect.w = canon.length;
canon_rect.h = canon.height;
canon_rect.x = terrain.x + canon.y;
canon_rect.y = terrain.y - canon.height;
//canon en noir
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &canon_rect);
}
void drawPointDeChuteSideView(){
//point de chute de la balle
point_de_chute.w = 5;
point_de_chute.h = 5;
point_de_chute.x = terrain.x + terrain.w/2 + point_y_rand;
point_de_chute.y = terrain.y;
//point de chute de la balle
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderFillRect(renderer, &point_de_chute);
}
void drawInformations(){
int texte_width = 200;
int texte_height = 40;
char str[20];
char zone_canon[20] = "zone canon : ";
int zone_ca = 4;
drawString("informations :", window_width-texte_width, texte_height*0, texte_width, texte_height, 255, 255, 255, 255);
drawString("e : new ball", window_width-texte_width, texte_height*1, texte_width, texte_height, 255, 255, 255, 255);
drawString("posBallX", window_width-texte_width, texte_height*2, texte_width, texte_height, 255, 255, 255, 255);
drawString("zone de chute : %d", window_width-texte_width, texte_height*3, texte_width, texte_height, 255, 255, 255, 255);
drawString("r : new canon", window_width-texte_width, texte_height*4, texte_width, texte_height, 255, 255, 255, 255);
drawString("position canon (%d, %d)", window_width-texte_width, texte_height*5, texte_width, texte_height, 255, 255, 255, 255);
sprintf(str, "%d", zone_ca);
strcat(zone_canon, str);
drawString(zone_canon, window_width-texte_width, texte_height*6, texte_width, texte_height, 255, 255, 255, 255);
}
void drawBall(){
/*int i;
SDL_Rect rect_life;
SDL_Rect rect_mana;
rect_life.h = 50;
rect_life.w = 50;
rect_life.x = 100;
rect_life.y = 100;
rect_mana.h = 50;
rect_mana.w = 50;
rect_mana.x = 100;
rect_mana.y = 200;*/
//draw hero life
/*SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
for(i=0; i<hero.life; i++){
SDL_RenderFillRect(renderer, &rect_life);
rect_life.x = rect_life.x + rect_life.w + 20;
}
//draw hero mana
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
for(i=0; i<hero.mana; i++){
SDL_RenderFillRect(renderer, &rect_mana);
rect_mana.x = rect_mana.x + rect_mana.w + 20;
}*/
}
void mainLoop(){
createWindow();
initCanon();
initPointDeChute(terrain);
//trouveZoneDeChute();
pthread_t eventThread;
if (pthread_create(&eventThread, NULL, eventLoop, NULL) != 0){
printf("Couldn't create thread.");
exit(EXIT_FAILURE);
}
while (running){
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
//top view
drawTerrainTopView();
drawCanonTopView();
drawPointDeChuteTopView();
//side view
drawTerrainSideView();
drawCanonSideView();
drawPointDeChuteSideView();
//
drawInformations();
SDL_RenderPresent(renderer);
}
endSDL();
}
\ No newline at end of file
#ifndef _RENDER_H_
#define _RENDER_H_
#include "gest_event.h"
#include "ball.h"
#include "canon.h"
void createWindow();
void endSDL();
void drawString(char *, int, int, int, int, int, int, int, int);
void drawTerrainTopView();
void initPointDeChute();
void newCanon();
//tofinish
void mainLoop();
#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