// File: /workspace/github_c_makefile_star2_O0/j4r0g[P]Projet_Labyrinthe/fonctions/labyrinthe.c
// Function: init_lab_rand
void init_lab_rand (t_lab lab[X][Y]){
	srand(time(NULL));
	int i, j, direction, i_tmp, j_tmp, a_lisse;
	int cases_extrude = 0;
	int ite_gauche = 0;
	int ite_droite = 0;
	int orientation = 0;
	for(i =0; i<X; i++){		//Ce bloc place des murs partout
		for(j =0; j<Y; j++){
			lab[i][j].etat = mur;
			lab[i][j].insecte = -1;
			if(j==0 || i==0 || j==(Y-1) || i==(X-1)){
				lab[i][j].decouvert = seen;
			}
			else{
				lab[i][j].decouvert = unseen;		//Cette ligne initialise "discover" pour toutes les cases du labyrinthe (au début, rien n'est découvert)
			}
		}
	}
	i = X/2;
	j = Y/2;
	while(cases_extrude < (X*Y)/2){			//Ce while va "extruder" des cases avec des murs, tant que la moitié du labyrinthe n'as pas été extrudé.
		lab[i][j].etat = vide;
		direction = nbr_rand(100);

		if(direction > 75 + orientation){	//le "+orientation" sert a faire partir le curseur qui va extruder vers la droite ou la gauche, lorsqu'on le replace au centre
			i_tmp = i;
			j_tmp = j-1;
			if(coord_correctes( i_tmp, j_tmp)){
				if(lab[i_tmp][j_tmp].etat == mur){
					lab[i_tmp][j_tmp].etat = vide;
					cases_extrude++;
				}
				i = i_tmp;
				j = j_tmp;
			}
		}

		else if(direction >50){
			i_tmp = i;
			j_tmp = j+1;
			if(coord_correctes( i_tmp, j_tmp)){
				if(lab[i_tmp][j_tmp].etat == mur){
					lab[i_tmp][j_tmp].etat = vide;
					cases_extrude++;
				}
				i = i_tmp;
				j = j_tmp;
			}
		}

		else if(direction >25){					//Envoie vers le haut le curseur.
			i_tmp = i-1;
			j_tmp = j;
			if(coord_correctes( i_tmp, j_tmp)){
				if(lab[i_tmp][j_tmp].etat == mur){
					lab[i_tmp][j_tmp].etat = vide;
					cases_extrude++;
				}
				i = i_tmp;
				j = j_tmp;

			}
		}

		else{							//Envoie le curseur vers le bas
			i_tmp = i+1;
			j_tmp = j;
			if(coord_correctes( i_tmp, j_tmp)){
				if(lab[i_tmp][j_tmp].etat == mur){
					lab[i_tmp][j_tmp].etat = vide;
					cases_extrude++;
				}
				j = j_tmp;
				i = i_tmp;
			}
		}

		if(j>3*(Y/5)){			//Ici, on regarde à chaques itérations si le curseur  est plutot du côté droit ou gauche (on incrémente ite_droite ou gauche en conséquence)
			ite_droite++;
		}
		else if(j<(Y/5)){
			ite_gauche++;
		}

		if(ite_droite> (X*Y)/4 ){	//Lorsque le curseur a extrudé plus d'un quart des murs a droite ou a gauche, on le remet au centre. On remet les statistiques a 0, mais on va utiliser la variable orientation
			i = X/2;				//Pour le faire partir préférentiellement du côté ou il a le moins "extrudé"
			j = Y/2;
			ite_gauche = 0;
			ite_droite = 0;
			orientation = -10;
		}
		else if(ite_gauche> (X*Y)/4 ){
			i = X/2;
			j = Y/2;
			ite_gauche = 0;
			ite_droite = 0;
			orientation = 10;
		}
	}

	a_lisse = lissage_lab(lab);	//Enfin, une fois que l'on a "extrudé" la moitié des murs, on utilise la fonction de "lissage", pour supprimer les murs trop abrupts
	while(a_lisse){
		a_lisse = lissage_lab(lab);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x10e0
movl %eax, %edi
callq 0x10a0
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x1e, -0xc(%rbp)
jge 0x1822
movl $0x0, -0x10(%rbp)
cmpl $0x3c, -0x10(%rbp)
jge 0x1812
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x23, 0x4(%rax)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
cmpl $0x0, -0x10(%rbp)
je 0x17ba
cmpl $0x0, -0xc(%rbp)
je 0x17ba
cmpl $0x3b, -0x10(%rbp)
je 0x17ba
cmpl $0x1d, -0xc(%rbp)
jne 0x17df
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
jmp 0x1802
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
jmp 0x1804
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1750
jmp 0x1814
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x173f
movl $0xf, -0xc(%rbp)
movl $0x1e, -0x10(%rbp)
cmpl $0x384, -0x24(%rbp)     # imm = 0x384
jge 0x1b10
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x20, 0x4(%rax)
movl $0x64, %edi
callq 0x13a0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl -0x30(%rbp), %ecx
addl $0x4b, %ecx
cmpl %ecx, %eax
jle 0x18ff
movl -0xc(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0x13c0
cmpl $0x0, %eax
je 0x18fa
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x23, 0x4(%rax)
jne 0x18ee
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x20, 0x4(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x1a8d
cmpl $0x32, -0x14(%rbp)
jle 0x1989
movl -0xc(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0x13c0
cmpl $0x0, %eax
je 0x1984
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x23, 0x4(%rax)
jne 0x1978
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x20, 0x4(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x1a8b
cmpl $0x19, -0x14(%rbp)
jle 0x1a0c
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0x13c0
cmpl $0x0, %eax
je 0x1a0a
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x23, 0x4(%rax)
jne 0x19fe
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x20, 0x4(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x1a89
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0x13c0
cmpl $0x0, %eax
je 0x1a87
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x23, 0x4(%rax)
jne 0x1a7b
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x20, 0x4(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x1a89
jmp 0x1a8b
jmp 0x1a8d
cmpl $0x24, -0x10(%rbp)
jle 0x1a9e
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1aaf
cmpl $0xc, -0x10(%rbp)
jge 0x1aad
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1aaf
cmpl $0x1c2, -0x2c(%rbp)     # imm = 0x1C2
jle 0x1add
movl $0xf, -0xc(%rbp)
movl $0x1e, -0x10(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0xfffffff6, -0x30(%rbp) # imm = 0xFFFFFFF6
jmp 0x1b0b
cmpl $0x1c2, -0x28(%rbp)     # imm = 0x1C2
jle 0x1b09
movl $0xf, -0xc(%rbp)
movl $0x1e, -0x10(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0xa, -0x30(%rbp)
jmp 0x1b0b
jmp 0x1830
movq -0x8(%rbp), %rdi
callq 0x1570
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x1b30
movq -0x8(%rbp), %rdi
callq 0x1570
movl %eax, -0x20(%rbp)
jmp 0x1b1c
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)