// File: antoniogarro[P]Hara/heuristics.cpp
// Function: Goban::fast_ladder(int, bool) const
bool Goban::fast_ladder(int point, bool color) const
{
  if (total_liberties(point, color, 0) != 2) return false;
  if (neighbour_groups(point, !color, 2, 0)) return false;
  PointList<5> liberties;
  point_liberties(point, liberties);
  for (int i = 0; i < liberties.length(); i++) {
    PointList<5> secondary_libs;
    int delta[2] = {0};
    if (point_liberties(liberties[i], secondary_libs) == 4) continue;
  
    delta[0] = liberties[i] - point;
    for (int j = 0; j < secondary_libs.length(); j++) {
      if (secondary_libs[j] != point && secondary_libs[j] != liberties[i] + delta[0]) {
        delta[1] = secondary_libs[j] - liberties[i];
        break;
      }
    }
    if (delta[1] == 0) return true;
    int p = point, act = 0;
    while (distance_to_edge[p] > 1) {
      p = p + delta[act];
      //look for ladder breakers. TODO: complete.
      if (points[p]) {
        if (points[p]->get_color() == color) break;
        else return true;
      }
      if (points[p + delta[act]]) {
        if (points[p + delta[act]]->get_color() == color) break;
        else return true;
      }
      act = 1-act;
    }
    if (distance_to_edge[p] < 2) return true;
  }
  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x80(%rbp)
movl -0x14(%rbp), %esi
movb -0x15(%rbp), %al
xorl %ecx, %ecx
movl %ecx, %r9d
xorl %r8d, %r8d
andb $0x1, %al
movzbl %al, %edx
movq %r9, %rcx
callq 0x105b0
cmpl $0x2, %eax
je 0xe5fa
movb $0x0, -0x1(%rbp)
jmp 0xe866
movq -0x80(%rbp), %rdi
movl -0x14(%rbp), %esi
movb -0x15(%rbp), %al
xorb $-0x1, %al
movzbl %al, %edx
andl $0x1, %edx
xorl %eax, %eax
movl %eax, %r8d
movl $0x2, %ecx
callq 0x7bb0
cmpl $0x0, %eax
je 0xe629
movb $0x0, -0x1(%rbp)
jmp 0xe866
leaq -0x38(%rbp), %rdi
callq 0x7580
movq -0x80(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x38(%rbp), %rdx
callq 0x7aa0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x84(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x76d0
movl %eax, %ecx
movl -0x84(%rbp), %eax
cmpl %ecx, %eax
jge 0xe862
leaq -0x60(%rbp), %rdi
callq 0x7580
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x3120
movl -0x3c(%rbp), %esi
leaq -0x38(%rbp), %rdi
callq 0x76b0
movq -0x80(%rbp), %rdi
movl %eax, %esi
leaq -0x60(%rbp), %rdx
callq 0x7aa0
cmpl $0x4, %eax
jne 0xe6a9
jmp 0xe854
movl -0x3c(%rbp), %esi
leaq -0x38(%rbp), %rdi
callq 0x76b0
subl -0x14(%rbp), %eax
movl %eax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x88(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x76d0
movl %eax, %ecx
movl -0x88(%rbp), %eax
cmpl %ecx, %eax
jge 0xe75b
movl -0x6c(%rbp), %esi
leaq -0x60(%rbp), %rdi
callq 0x76b0
cmpl -0x14(%rbp), %eax
je 0xe74b
movl -0x6c(%rbp), %esi
leaq -0x60(%rbp), %rdi
callq 0x76b0
movl %eax, -0x8c(%rbp)
movl -0x3c(%rbp), %esi
leaq -0x38(%rbp), %rdi
callq 0x76b0
movl %eax, %ecx
movl -0x8c(%rbp), %eax
addl -0x68(%rbp), %ecx
cmpl %ecx, %eax
je 0xe74b
movl -0x6c(%rbp), %esi
leaq -0x60(%rbp), %rdi
callq 0x76b0
movl %eax, -0x90(%rbp)
movl -0x3c(%rbp), %esi
leaq -0x38(%rbp), %rdi
callq 0x76b0
movl %eax, %ecx
movl -0x90(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x64(%rbp)
jmp 0xe75b
jmp 0xe74d
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xe6c2
cmpl $0x0, -0x64(%rbp)
jne 0xe76a
movb $0x1, -0x1(%rbp)
jmp 0xe866
movl -0x14(%rbp), %eax
movl %eax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movq -0x80(%rbp), %rax
movslq -0x70(%rbp), %rcx
cmpl $0x1, 0xdf6f8(%rax,%rcx,4)
jle 0xe83a
movq -0x80(%rbp), %rax
movl -0x70(%rbp), %ecx
movslq -0x74(%rbp), %rdx
addl -0x68(%rbp,%rdx,4), %ecx
movl %ecx, -0x70(%rbp)
movslq -0x70(%rbp), %rcx
cmpq $0x0, 0x18(%rax,%rcx,8)
je 0xe7da
movq -0x80(%rbp), %rax
movslq -0x70(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rdi
callq 0x7400
andb $0x1, %al
movzbl %al, %eax
movb -0x15(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0xe7d1
jmp 0xe83a
movb $0x1, -0x1(%rbp)
jmp 0xe866
movq -0x80(%rbp), %rax
movl -0x70(%rbp), %ecx
movslq -0x74(%rbp), %rdx
addl -0x68(%rbp,%rdx,4), %ecx
movslq %ecx, %rcx
cmpq $0x0, 0x18(%rax,%rcx,8)
je 0xe82a
movq -0x80(%rbp), %rax
movl -0x70(%rbp), %ecx
movslq -0x74(%rbp), %rdx
addl -0x68(%rbp,%rdx,4), %ecx
movslq %ecx, %rcx
movq 0x18(%rax,%rcx,8), %rdi
callq 0x7400
andb $0x1, %al
movzbl %al, %eax
movb -0x15(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0xe824
jmp 0xe83a
movb $0x1, -0x1(%rbp)
jmp 0xe866
movl $0x1, %eax
subl -0x74(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0xe777
movq -0x80(%rbp), %rax
movslq -0x70(%rbp), %rcx
cmpl $0x2, 0xdf6f8(%rax,%rcx,4)
jge 0xe852
movb $0x1, -0x1(%rbp)
jmp 0xe866
jmp 0xe854
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xe649
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)