// File: KellerMartins[P]PDS2-Pacman/source/game/mapa.cpp
// Function: Mapa::GerarCaminho()
void Mapa::GerarCaminho(){
	//Criando a matriz geradora de caminhos
	int** caminhos = new int*[LARGURA*ALTURA];
	for(int i = 0; i < LARGURA*ALTURA; i++){
		caminhos[i] = new int[LARGURA*ALTURA];
	}
	//Inicializando
	for(int i = 0; i < LARGURA*ALTURA; i++){
		for(int j = 0; j < LARGURA*ALTURA; j++){
			caminhos[i][j] = INT_MAX/2;
			_proximo[i][j] = -1;
		}
	}

	for(int y = 0; y < ALTURA; y++){
		for(int x = 0; x < LARGURA; x++){
			int i = x+(y*LARGURA);
			caminhos[i][i] = 0;
			_proximo[i][i] = i;

			//Define a distancia entre vizinhos e o atual como 1
			if(_mapa[x][y] != Parede){
				if(x+1 < LARGURA && _mapa[x+1][y]!=Parede){
					int iv = (x+1)+(y*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}else if(x == LARGURA){
					int iv = 0+(y*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}

				if(x-1 >= 0 && _mapa[x-1][y]!=Parede){
					int iv = (x-1)+(y*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}else if(x == 0){
					int iv = (LARGURA-1)+(y*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}

				if(y+1 < ALTURA && _mapa[x][y+1]!=Parede){
					int iv = x +((y+1)*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}else if(y == ALTURA){
					int iv = x+(0*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}

				if(y-1 >= 0 && _mapa[x][y-1]!=Parede){
					int iv = x +((y-1)*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}else if(y == 0){
					int iv = x+((ALTURA-1)*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}
			}			
		}
	}

	for(int k = 0; k < LARGURA*ALTURA; k++){
		for(int i = 0; i < LARGURA*ALTURA; i++){
			for(int j = 0; j < LARGURA*ALTURA; j++){
				if(caminhos[i][j] > caminhos[i][k] + caminhos[k][j]){
					caminhos[i][j] = caminhos[i][k] + caminhos[k][j];
					_proximo[i][j] = _proximo[i][k];
				}
			}
		}
	}

	for(int i = 0; i < LARGURA*ALTURA; i++){
		free(caminhos[i]);
	}
	free(caminhos);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x11b8, %edi           # imm = 0x11B8
callq 0x9050
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x237, -0x14(%rbp)     # imm = 0x237
jge 0xfa56
movl $0x8dc, %edi            # imm = 0x8DC
callq 0x9050
movq %rax, %rdx
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xfa29
movl $0x0, -0x18(%rbp)
cmpl $0x237, -0x18(%rbp)     # imm = 0x237
jge 0xfac8
movl $0x0, -0x1c(%rbp)
cmpl $0x237, -0x1c(%rbp)     # imm = 0x237
jge 0xfabb
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq -0x18(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x1c(%rbp), %rdx
movl $0x3fffffff, (%rcx,%rdx,4) # imm = 0x3FFFFFFF
addq $0x1218, %rax           # imm = 0x1218
movslq -0x18(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xfa6d
jmp 0xfabd
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xfa5d
movl $0x0, -0x20(%rbp)
cmpl $0x1b, -0x20(%rbp)
jge 0x10073
movl $0x0, -0x24(%rbp)
cmpl $0x15, -0x24(%rbp)
jge 0x10063
movq -0x60(%rbp), %rax
movl -0x24(%rbp), %ecx
imull $0x15, -0x20(%rbp), %edx
addl %edx, %ecx
movl %ecx, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x28(%rbp), %rdx
movl $0x0, (%rcx,%rdx,4)
movl -0x28(%rbp), %esi
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x28(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x28(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
addq $0x8, %rax
movslq -0x24(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
cmpl $0x1, (%rax,%rcx,4)
je 0x10053
movl -0x24(%rbp), %eax
addl $0x1, %eax
cmpl $0x15, %eax
jge 0xfc0b
movq -0x60(%rbp), %rax
addq $0x8, %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
cmpl $0x1, (%rax,%rcx,4)
je 0xfc0b
movq -0x60(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
imull $0x15, -0x20(%rbp), %edx
addl %edx, %ecx
movl %ecx, -0x2c(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x2c(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movq -0x10(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x28(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movl -0x2c(%rbp), %esi
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x28(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x2c(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x28(%rbp), %edx
addq $0x1218, %rax           # imm = 0x1218
movslq -0x2c(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xfc8f
cmpl $0x15, -0x24(%rbp)
jne 0xfc8d
movq -0x60(%rbp), %rax
imull $0x15, -0x20(%rbp), %ecx
addl $0x0, %ecx
movl %ecx, -0x30(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x30(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movq -0x10(%rbp), %rcx
movslq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x28(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movl -0x30(%rbp), %esi
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x28(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x30(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x28(%rbp), %edx
addq $0x1218, %rax           # imm = 0x1218
movslq -0x30(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xfc8f
movl -0x24(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0xfd4a
movq -0x60(%rbp), %rax
addq $0x8, %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
cmpl $0x1, (%rax,%rcx,4)
je 0xfd4a
movq -0x60(%rbp), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
imull $0x15, -0x20(%rbp), %edx
addl %edx, %ecx
movl %ecx, -0x34(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x34(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movq -0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x28(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movl -0x34(%rbp), %esi
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x28(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x34(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x28(%rbp), %edx
addq $0x1218, %rax           # imm = 0x1218
movslq -0x34(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xfdce
cmpl $0x0, -0x24(%rbp)
jne 0xfdcc
movq -0x60(%rbp), %rax
imull $0x15, -0x20(%rbp), %ecx
addl $0x14, %ecx
movl %ecx, -0x38(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x38(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movq -0x10(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x28(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movl -0x38(%rbp), %esi
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x28(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x38(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x28(%rbp), %edx
addq $0x1218, %rax           # imm = 0x1218
movslq -0x38(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xfdce
movl -0x20(%rbp), %eax
addl $0x1, %eax
cmpl $0x1b, %eax
jge 0xfe8b
movq -0x60(%rbp), %rax
addq $0x8, %rax
movslq -0x24(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x1, (%rax,%rcx,4)
je 0xfe8b
movq -0x60(%rbp), %rax
movl -0x24(%rbp), %ecx
movl -0x20(%rbp), %edx
addl $0x1, %edx
imull $0x15, %edx, %edx
addl %edx, %ecx
movl %ecx, -0x3c(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x3c(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movq -0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x28(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movl -0x3c(%rbp), %esi
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x28(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x3c(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x28(%rbp), %edx
addq $0x1218, %rax           # imm = 0x1218
movslq -0x3c(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xff0e
cmpl $0x1b, -0x20(%rbp)
jne 0xff0c
movq -0x60(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x0, %ecx
movl %ecx, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x40(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movq -0x10(%rbp), %rcx
movslq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x28(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movl -0x40(%rbp), %esi
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x28(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x40(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x28(%rbp), %edx
addq $0x1218, %rax           # imm = 0x1218
movslq -0x40(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xff0e
movl -0x20(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0xffcb
movq -0x60(%rbp), %rax
addq $0x8, %rax
movslq -0x24(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x1, (%rax,%rcx,4)
je 0xffcb
movq -0x60(%rbp), %rax
movl -0x24(%rbp), %ecx
movl -0x20(%rbp), %edx
subl $0x1, %edx
imull $0x15, %edx, %edx
addl %edx, %ecx
movl %ecx, -0x44(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x44(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movq -0x10(%rbp), %rcx
movslq -0x44(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x28(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movl -0x44(%rbp), %esi
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x28(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x44(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x28(%rbp), %edx
addq $0x1218, %rax           # imm = 0x1218
movslq -0x44(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x10051
cmpl $0x0, -0x20(%rbp)
jne 0x1004f
movq -0x60(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x222, %ecx            # imm = 0x222
movl %ecx, -0x48(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x48(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movq -0x10(%rbp), %rcx
movslq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x28(%rbp), %rdx
movl $0x1, (%rcx,%rdx,4)
movl -0x48(%rbp), %esi
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x28(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x48(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x28(%rbp), %edx
addq $0x1218, %rax           # imm = 0x1218
movslq -0x48(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x10051
jmp 0x10053
jmp 0x10055
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xfae0
jmp 0x10065
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xfacf
movl $0x0, -0x4c(%rbp)
cmpl $0x237, -0x4c(%rbp)     # imm = 0x237
jge 0x10193
movl $0x0, -0x50(%rbp)
cmpl $0x237, -0x50(%rbp)     # imm = 0x237
jge 0x10183
movl $0x0, -0x54(%rbp)
cmpl $0x237, -0x54(%rbp)     # imm = 0x237
jge 0x10173
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x54(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movslq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movq -0x10(%rbp), %rdx
movslq -0x4c(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
movslq -0x54(%rbp), %rsi
addl (%rdx,%rsi,4), %ecx
cmpl %ecx, %eax
jle 0x10163
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x4c(%rbp), %rdx
movl (%rcx,%rdx,4), %esi
movq -0x10(%rbp), %rcx
movslq -0x4c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x54(%rbp), %rdx
addl (%rcx,%rdx,4), %esi
movq -0x10(%rbp), %rcx
movslq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x54(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movq %rax, %rcx
addq $0x1218, %rcx           # imm = 0x1218
movslq -0x50(%rbp), %rdx
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %rdx, %rcx
movslq -0x4c(%rbp), %rdx
movl (%rcx,%rdx,4), %edx
addq $0x1218, %rax           # imm = 0x1218
movslq -0x50(%rbp), %rcx
imulq $0x8dc, %rcx, %rcx      # imm = 0x8DC
addq %rcx, %rax
movslq -0x54(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x10165
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x100a2
jmp 0x10175
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x1008e
jmp 0x10185
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1007a
movl $0x0, -0x58(%rbp)
cmpl $0x237, -0x58(%rbp)     # imm = 0x237
jge 0x101bf
movq -0x10(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x9a40
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1019a
movq -0x10(%rbp), %rdi
callq 0x9a40
addq $0x60, %rsp
popq %rbp
retq
nop