// File: /workspace/github_cpp_makefile_star2_O3/jenniferdr[P]proyectoIAI/main.cc
// Function: main
int main(int argc, char *argv[]){

  if(argc!=5){
    std::cout << 
      "Error. Sintaxis: <algoritmo> <heuristica> <peso(W)> <archivo_iniciales>";
    std::cout << std::endl << "heuristica: manhattan, Mconflictos, static555 ";
    std::cout << std::endl << "algoritmo: a_estrella ida_estrella" << std::endl;
    return 1;
  }
  std::string algoritmo= std::string(argv[1]);
  if(algoritmo!= "a_estrella" && algoritmo!= "ida_estrella"){
    std::cout << "Error: algoritmo no valido";
    return 1;
  }
  std::string heuristica= std::string(argv[2]);
  if(heuristica!= "manhattan" && heuristica!= "Mconflictos"
     && heuristica!= "static555"){
    std::cout << "Error: heuristica no valida";
    return 1;
  }
  if(atoi(argv[3])<=0){
    std::cout << "Error: el peso debe ser mayor o igual a 1";
    return 1;
  }
  peso= atoi(argv[3]);
  
  std::ifstream archivo(argv[4]);
  
  if(!archivo){
    std::cout << "Ha fallado la lectura" << std::endl;
    return -1;
  }
  generarBD();
  generarTabla();
  char linea[40];

  while(archivo.getline(linea,40)){
    std::cout << linea << " : ";

    char estado[16];
    
    std::istringstream stream(linea,std::istringstream::in);
    for(int i=0; i<16;i++){
      char tile[3];
      stream >> tile;
      estado[i]= atoi(tile);
    }

    std::list<Nodo*> listaResuelto;
    Nodo *nodoResuelto;

    if(algoritmo=="a_estrella"){
      if(heuristica=="manhattan") nodoResuelto= a_manhattan(estado,peso);
      if(heuristica=="Mconflictos") nodoResuelto= a_conflictos(estado,peso);
      if(heuristica=="static555") nodoResuelto= a_static555(estado,peso);
    } 
    if(algoritmo=="ida_estrella"){
      if(heuristica=="manhattan") listaResuelto= ida_manhattan(estado);
      if(heuristica=="Mconflictos") listaResuelto= ida_conflictos(estado);
      if(heuristica=="static555") listaResuelto= ida_static555(estado);
      std::cout << " " << (int) listaResuelto.back()->distancia;
    }

    std::cout << "\n --- \n" << std::endl;
    /*    Nodo* res = a_static555(estado, 1);
	  extract_solution(res);*/
  }
 
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
cmpl $0x5, %edi
jne 0x4a3c
movq %rsi, %rbx
movq 0x8(%rsi), %rsi
leaq 0x70(%rsp), %r14
leaq 0x240(%rsp), %rdx
movq %r14, %rdi
callq 0x5144
leaq 0x179e(%rip), %rsi      # 0x618f
movq %r14, %rdi
callq 0x2090
testl %eax, %eax
je 0x4b01
leaq 0x1785(%rip), %rsi      # 0x618d
leaq 0x70(%rsp), %rdi
callq 0x2090
testl %eax, %eax
je 0x4b01
movl $0x1, %ebx
movq 0x45b2(%rip), %rdi      # 0x8fd8
leaq 0x176d(%rip), %rsi      # 0x619a
movl $0x1a, %edx
callq 0x21a0
jmp 0x5039
movq 0x4595(%rip), %rbx      # 0x8fd8
leaq 0x16b6(%rip), %rsi      # 0x6100
movl $0x47, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
leaq 0x16c3(%rip), %rsi      # 0x6148
movl $0x2e, %edx
movq %rax, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %rax, %rbx
leaq 0x16b4(%rip), %rsi      # 0x6177
movl $0x22, %edx
movq %rax, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movl $0x1, %ebx
jmp 0x505a
movq 0x10(%rbx), %rsi
leaq 0x38(%rsp), %rdi
leaq 0x240(%rsp), %rdx
callq 0x5144
leaq 0x1697(%rip), %rsi      # 0x61b5
leaq 0x38(%rsp), %rdi
callq 0x2090
testl %eax, %eax
je 0x4b67
leaq 0x168c(%rip), %rsi      # 0x61bf
leaq 0x38(%rsp), %rdi
callq 0x2090
testl %eax, %eax
je 0x4b67
leaq 0x1683(%rip), %rsi      # 0x61cb
leaq 0x38(%rsp), %rdi
callq 0x2090
testl %eax, %eax
je 0x4b67
movl $0x1b, %edx
leaq 0x1673(%rip), %rsi      # 0x61d5
jmp 0x4c0c
movq 0x18(%rbx), %rdi
callq 0x2230
testl %eax, %eax
jle 0x4c00
leaq 0x30447c5(%rip), %rcx   # 0x3049344
movl %eax, (%rcx)
movq 0x20(%rbx), %rsi
leaq 0x240(%rsp), %r12
movq %r12, %rdi
movl $0x8, %edx
callq 0x22d0
movq 0x240(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x260(%rsp,%rax)
je 0x4c22
movq 0x4421(%rip), %rbx      # 0x8fd8
leaq 0x165d(%rip), %rsi      # 0x621b
movl $0x15, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0x43ef(%rip), %rdi      # 0x8fd8
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2110
jmp 0x5011
movl $0x29, %edx
leaq 0x15e5(%rip), %rsi      # 0x61f1
movl $0x1, %ebx
movq 0x43c0(%rip), %rdi      # 0x8fd8
callq 0x21a0
jmp 0x501e
callq 0x3a73
callq 0x41e4
leaq 0x10(%rsp), %rbp
leaq 0x90(%rsp), %r13
movq 0x4398(%rip), %r15      # 0x8fd8
movq %rsp, %r14
leaq 0xc0(%rsp), %rbx
movq 0x240(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %ecx
movl $0x28, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x22e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x500f
movq %r13, %rdi
callq 0x20e0
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x21a0
movl $0x3, %edx
movq %r15, %rdi
leaq 0x1583(%rip), %rsi      # 0x6231
callq 0x21a0
movq %rbp, (%rsp)
movq %r13, %rdi
callq 0x20e0
leaq (%rsp,%rax), %rdx
addq $0x90, %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x5182
movq %rbx, %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x2260
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0x4cfb
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2190
xorl %ebp, %ebp
movq 0xc0(%rsp), %rax
movq -0x18(%rax), %rax
movq 0xd0(%rsp,%rax), %r12
movl $0x3, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2290
movq 0xc0(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0xe0(%rsp,%rax)
jne 0x4d53
addq $-0x4, %r12
cmpq $-0x4, %r12
ja 0x4d53
movq 0x1a8(%rsp,%rax), %rdi
movq 0x10(%rdi), %rax
cmpq 0x18(%rdi), %rax
jae 0x4d6a
movq %r14, %rdi
callq 0x2230
movb %al, 0x20(%rsp,%rbp)
incq %rbp
cmpq $0x10, %rbp
jne 0x4cfd
jmp 0x4d99
movq (%rdi), %rax
callq *0x48(%rax)
cmpl $-0x1, %eax
jne 0x4d53
movq 0xc0(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%rsp,%rax), %rdi
addq $0xc0, %rdi
movl 0x20(%rdi), %esi
orl $0x2, %esi
callq 0x2270
jmp 0x4d53
movq %r14, 0x8(%rsp)
movq %r14, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x13d8(%rip), %rsi      # 0x618f
callq 0x2090
testl %eax, %eax
leaq 0x10(%rsp), %rbp
leaq 0x38(%rsp), %r12
jne 0x4e3c
movq %r12, %rdi
leaq 0x13e1(%rip), %rsi      # 0x61b5
callq 0x2090
testl %eax, %eax
jne 0x4df0
leaq 0x3044560(%rip), %rax   # 0x3049344
movl (%rax), %esi
leaq 0x20(%rsp), %rdi
callq 0x2a90
movq %r12, %rdi
leaq 0x13c5(%rip), %rsi      # 0x61bf
callq 0x2090
testl %eax, %eax
jne 0x4e16
leaq 0x304453a(%rip), %rax   # 0x3049344
movl (%rax), %esi
leaq 0x20(%rsp), %rdi
callq 0x2ab4
movq %r12, %rdi
leaq 0x13ab(%rip), %rsi      # 0x61cb
callq 0x2090
testl %eax, %eax
jne 0x4e3c
leaq 0x3044514(%rip), %rax   # 0x3049344
movl (%rax), %esi
leaq 0x20(%rsp), %rdi
callq 0x2a84
leaq 0x70(%rsp), %rdi
leaq 0x1345(%rip), %rsi      # 0x618d
callq 0x2090
testl %eax, %eax
jne 0x4f8d
movq %r12, %rdi
leaq 0x1356(%rip), %rsi      # 0x61b5
callq 0x2090
testl %eax, %eax
jne 0x4eb1
leaq 0x58(%rsp), %r12
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x47cf
movq %r14, %rdi
movq %r12, %rsi
callq 0x5218
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x4ea7
movq %r12, %rbp
movq (%rdi), %r12
movl $0x18, %esi
callq 0x2190
movq %r12, %rdi
cmpq %rbp, %r12
jne 0x4e92
leaq 0x38(%rsp), %r12
leaq 0x10(%rsp), %rbp
movq %r12, %rdi
leaq 0x1304(%rip), %rsi      # 0x61bf
callq 0x2090
testl %eax, %eax
jne 0x4f0d
leaq 0x58(%rsp), %r12
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x493d
movq %r14, %rdi
movq %r12, %rsi
callq 0x5218
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x4f03
movq %r12, %rbp
movq (%rdi), %r12
movl $0x18, %esi
callq 0x2190
movq %r12, %rdi
cmpq %rbp, %r12
jne 0x4eee
leaq 0x38(%rsp), %r12
leaq 0x10(%rsp), %rbp
movq %r12, %rdi
leaq 0x12b4(%rip), %rsi      # 0x61cb
callq 0x2090
testl %eax, %eax
jne 0x4f64
leaq 0x58(%rsp), %r12
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x4755
movq %r14, %rdi
movq %r12, %rsi
callq 0x5218
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x4f5f
movq %r12, %rbp
movq (%rdi), %r12
movl $0x18, %esi
callq 0x2190
movq %r12, %rdi
cmpq %rbp, %r12
jne 0x4f4a
leaq 0x10(%rsp), %rbp
movl $0x1, %edx
movq %r15, %rdi
leaq 0x1202(%rip), %rsi      # 0x6175
callq 0x21a0
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movsbl 0x10(%rax), %esi
movq %r15, %rdi
callq 0x22a0
movl $0x7, %edx
movq %r15, %rdi
leaq 0x1299(%rip), %rsi      # 0x6235
callq 0x21a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x4fe6
movq (%rdi), %r12
movl $0x18, %esi
callq 0x2190
movq %r12, %rdi
cmpq %r14, %r12
jne 0x4fd1
movq %rbx, %rdi
movq 0x3fe0(%rip), %rsi      # 0x8fd0
callq 0x21f0
leaq 0x138(%rsp), %rdi
callq 0x20a0
leaq 0x240(%rsp), %r12
jmp 0x4c4b
xorl %ebx, %ebx
leaq 0x240(%rsp), %rdi
callq 0x2070
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5039
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x505a
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2190
movl %ebx, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5070
movq %rax, %rbx
jmp 0x5100
jmp 0x5080
jmp 0x50ac
jmp 0x50ac
jmp 0x50ac
movq %rax, %rbx
jmp 0x511b
jmp 0x50a7
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0x50f3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2190
jmp 0x50f3
jmp 0x50a7
movq %rax, %rbx
jmp 0x50f3
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x50d2
movq (%rdi), %r15
movl $0x18, %esi
callq 0x2190
movq %r15, %rdi
cmpq %r14, %r15
jne 0x50b8
jmp 0x50d2
movq %rax, %rbx
movq 0x3ef7(%rip), %rsi      # 0x8fd0
leaq 0xc0(%rsp), %rdi
callq 0x21f0
leaq 0x138(%rsp), %rdi
callq 0x20a0
leaq 0x240(%rsp), %rdi
callq 0x2070
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x511b
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x513c
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x22b0