// File: antoniogarro[P]Hara/engine.cpp
// Function: Engine::score(std::vector<int, std::allocator<int>>*)
float Engine::score(std::vector<int> *dead)
{
  const int PLAYOUTS = 5000;
  int score = 0;
  int score_table[MAXSIZE2+1] = {0};
  for (int i = 0; i < PLAYOUTS; i++) {
    simul_len = 0;
    play_random_game(LIGHT);
    main_goban->score_area(score_table);
    main_goban->restore();
  }
  for (int i = 1; i <= main_goban->get_size2(); i++) {
    if (score_table[i] > PLAYOUTS/2) score_table[i] = 1;
    else if (score_table[i] < -PLAYOUTS/2) score_table[i] = -1;
    else score_table[i] = 0;
    
    if (dead && main_goban->get_value(i)
        && score_table[i] !=  main_goban->get_value(i)) {
      dead->insert(dead->end(), i);
    }
  }

  for (int i = 1; i <= main_goban->get_size2(); i++) {
    score += score_table[i];
  }
  return score - main_goban->get_komi();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x610, %rsp            # imm = 0x610
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x5f0(%rbp)
movl $0x1388, -0x14(%rbp)    # imm = 0x1388
movl $0x0, -0x18(%rbp)
leaq -0x5c0(%rbp), %rdi
xorl %esi, %esi
movl $0x5a8, %edx            # imm = 0x5A8
callq 0x3120
movl $0x0, -0x5c4(%rbp)
cmpl $0x1388, -0x5c4(%rbp)   # imm = 0x1388
jge 0x42c8
movq -0x5f0(%rbp), %rdi
movl $0x0, 0x1c(%rdi)
movb 0x1(%rdi), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x3b10
movq -0x5f0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x5c0(%rbp), %rsi
callq 0x8490
movq -0x5f0(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x6540
movl -0x5c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c4(%rbp)
jmp 0x4269
movl $0x1, -0x5c8(%rbp)
movq -0x5f0(%rbp), %rax
movl -0x5c8(%rbp), %ecx
movl %ecx, -0x5f4(%rbp)
movq 0x8(%rax), %rdi
callq 0x46c0
movl %eax, %ecx
movl -0x5f4(%rbp), %eax
cmpl %ecx, %eax
jg 0x4427
movslq -0x5c8(%rbp), %rax
cmpl $0x9c4, -0x5c0(%rbp,%rax,4) # imm = 0x9C4
jle 0x4326
movslq -0x5c8(%rbp), %rax
movl $0x1, -0x5c0(%rbp,%rax,4)
jmp 0x4362
movslq -0x5c8(%rbp), %rax
cmpl $0xfffff63c, -0x5c0(%rbp,%rax,4) # imm = 0xFFFFF63C
jge 0x434e
movslq -0x5c8(%rbp), %rax
movl $0xffffffff, -0x5c0(%rbp,%rax,4) # imm = 0xFFFFFFFF
jmp 0x4360
movslq -0x5c8(%rbp), %rax
movl $0x0, -0x5c0(%rbp,%rax,4)
jmp 0x4362
cmpq $0x0, -0x10(%rbp)
je 0x4411
movq -0x5f0(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x5c8(%rbp), %esi
callq 0x8330
cmpl $0x0, %eax
je 0x4411
movq -0x5f0(%rbp), %rax
movslq -0x5c8(%rbp), %rcx
movl -0x5c0(%rbp,%rcx,4), %ecx
movl %ecx, -0x5f8(%rbp)
movq 0x8(%rax), %rdi
movl -0x5c8(%rbp), %esi
callq 0x8330
movl %eax, %ecx
movl -0x5f8(%rbp), %eax
cmpl %ecx, %eax
je 0x4411
movq -0x10(%rbp), %rax
movq %rax, -0x600(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4980
movq %rax, -0x5d8(%rbp)
leaq -0x5d0(%rbp), %rdi
leaq -0x5d8(%rbp), %rsi
callq 0x49b0
movq -0x600(%rbp), %rdi
movq -0x5d0(%rbp), %rsi
leaq -0x5c8(%rbp), %rdx
callq 0x4780
movq %rax, -0x5e0(%rbp)
jmp 0x4413
movl -0x5c8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c8(%rbp)
jmp 0x42d2
movl $0x1, -0x5e4(%rbp)
movq -0x5f0(%rbp), %rax
movl -0x5e4(%rbp), %ecx
movl %ecx, -0x604(%rbp)
movq 0x8(%rax), %rdi
callq 0x46c0
movl %eax, %ecx
movl -0x604(%rbp), %eax
cmpl %ecx, %eax
jg 0x447e
movslq -0x5e4(%rbp), %rax
movl -0x5c0(%rbp,%rax,4), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x5e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5e4(%rbp)
jmp 0x4431
movq -0x5f0(%rbp), %rax
cvtsi2ssl -0x18(%rbp), %xmm0
movss %xmm0, -0x608(%rbp)
movq 0x8(%rax), %rdi
callq 0x49f0
movaps %xmm0, %xmm1
movss -0x608(%rbp), %xmm0
subss %xmm1, %xmm0
addq $0x610, %rsp            # imm = 0x610
popq %rbp
retq
nopw %cs:(%rax,%rax)