// File: /workspace/github_cpp_makefile_star2_O2/tanakh[P]icfpc2015/main.cpp
// Function: calc_score(std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>&, std::complex<int> const&, unit const&, int, int, std::vector<int, std::allocator<int>> const&)
double calc_score(vector<vector<int>> &bd,
                  const pt &pos, const unit &u, int rot, int ls_old,
                  const vector<int> &cmds)
{
  int w = bd[0].size(), h = bd.size();

  static vector<pt> units;
  static vector<pt> pts;
  units.clear();
  pts.clear();

  double height = h;
  double feat[FN] = {};

  for (auto &c: u.members) {
    auto d = rot_pivot(c + pos, u.pivot + pos, rot);
    height = min(height, (double)d.imag());

    units.push_back(d);
    pts.push_back(d);
    for (int i = 0; i < 6; i++) {
      int cx = d.real() + adj6[i][0];
      int cy = d.imag() + adj6[i][1];

      if (!(cx >= 0 && cx < w && cy >= 0 && cy < h)) continue;
      pts.push_back(pt(cx, cy));
    }
  }

  for (auto &p: pts) {
    int cx = p.real();
    int cy = p.imag();
    if (bd[cy][cx] & (1 << 8)) continue;
    bd[cy][cx] |= (1 << 8);

    if ((bd[cy][cx] & ((1<<8)-1)) != 0) continue;

    int pat = 0;
    for (int i = 0; i < 6; i++) {
      int dx = cx + adj6[i][0];
      int dy = cy + adj6[i][1];

      if (!(dx >= 0 && dx < w && dy >= 0 && dy < h &&
            (bd[dy][dx] & ((1<<8)-1)) == 0))
        continue;

      pat |= (1 << i);
    }

    int f = 0;
    f = f * 3 + ((pat>>0)&1) + ((pat>>1)&1);
    f = f * 3 + ((pat>>2)&1) + ((pat>>3)&1);
    feat[f]++;
  }

  for (auto &p: pts)
    bd[p.imag()][p.real()] &= ~(1 << 8);

  for (auto &c: units)
    bd[c.imag()][c.real()] = 1;

  for (auto &p: pts) {
    int cx = p.real();
    int cy = p.imag();
    if (bd[cy][cx] & (1 << 8)) continue;
    bd[cy][cx] |= (1 << 8);

    if ((bd[cy][cx] & ((1<<8)-1)) != 0) continue;

    int pat = 0;
    for (int i = 0; i < 6; i++) {
      int dx = cx + adj6[i][0];
      int dy = cy + adj6[i][1];

      if (!(dx >= 0 && dx < w && dy >= 0 && dy < h &&
            (bd[dy][dx] & ((1<<8)-1)) == 0))
        continue;

      pat |= (1 << i);
    }

    int f = 0;
    f = f * 3 + ((pat>>0)&1) + ((pat>>1)&1);
    f = f * 3 + ((pat>>2)&1) + ((pat>>3)&1);
    feat[f]--;
  }

  for (auto &p: pts)
    bd[p.imag()][p.real()] &= ~(1 << 8);

  for (auto &c: units)
    bd[c.imag()][c.real()] = 0;

  double ret = 0;

  for (int i = 0; i < FN; i++)
    ret += eparam[i] * feat[i];

  ret += eparam[FN + 0] * height * w;

  return ret;

  // int w = bd[0].size(), h = bd.size();

  // double height = h;

  // for (int y = 0; y < h; y++) {
  //   for (int x = 0; x < w/2; x++) {
  //     int xx = x*2 + y%2;
  //     if (bd[y][xx] != 0) {
  //       height = min(height, (double)y);
  //     }

  //     if (bd[y][xx] != 0)
  //       continue;

  //     const int vect[][2] = {
  //       {-1, -1},
  //       {1, -1},
  //       {2, 0},
  //       {-2, 0},
  //       {1, 1},
  //       {-1, 1},
  //     };

  //     int pat = 0;
  //     for (int i = 0; i < 6; i++) {
  //       int cx = xx + vect[i][0];
  //       int cy = y + vect[i][1];

  //       if (!(cx >= 0 && cx < w && cy >= 0 && cy < h && bd[cy][cx] == 0)) continue;

  //       pat |= (1 << i);
  //     }

  //     int f = 0;
  //     f = f * 3 + ((pat>>0)&1) + ((pat>>1)&1);
  //     f = f * 3 + ((pat>>2)&1) + ((pat>>3)&1);
  //     // f = f * 3 + ((pat>>4)&1) + ((pat>>5)&1);
  //     // f = f * 2 + (bd[y][xx] != 0);

  //     feat[f]++;
  //   }
  // }

  // double ret = 0;

  // // vlog() << height << ", " << holes << ", " << roofs << ", " << sides << endl;
  // // height /= h;
  // // if (height >= 0.8) height = 1;

  // for (int i = 0; i < FN; i++)
  //   ret += eparam[i] * feat[i];

  // ret += eparam[FN + 0] * height * w;
  // ret += eparam[FN + 1] * (double)last.imag() * w;
  // ret += eparam[FN + 2] * (double)(lines+1)*lines/2 * w * h;
  // // ret += eparam[FN + 3] * (double)cmds.length();

  // return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %ecx, 0x1c(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x38(%rsp)
movq (%rdi), %rcx
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %rax
movq 0x8(%rcx), %r15
subq (%rcx), %r15
subq %rcx, %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, %r14
movb 0x18a85(%rip), %al      # 0x1d870
testb %al, %al
je 0x5251
movb 0x18a97(%rip), %al      # 0x1d890
testb %al, %al
je 0x52a2
movq 0x18a50(%rip), %rax     # 0x1d858
cmpq %rax, 0x18a51(%rip)     # 0x1d860
je 0x4e18
movq %rax, 0x18a48(%rip)     # 0x1d860
shrq $0x2, %r15
movq 0x18a55(%rip), %rax     # 0x1d878
cmpq %rax, 0x18a56(%rip)     # 0x1d880
je 0x4e33
movq %rax, 0x18a4d(%rip)     # 0x1d880
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
andq $0x0, 0xa0(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0x28(%rsp), %r13
leaq 0x189f2(%rip), %rbp     # 0x1d878
leaq 0xd2e3(%rip), %rbx      # 0x12170
cmpq 0x40(%rsp), %rcx
je 0x4f8e
movq %rcx, 0x50(%rsp)
movq (%rcx), %rax
movq 0x38(%rsp), %rsi
movl (%rsi), %ecx
leal (%rcx,%rax), %edx
shrq $0x20, %rax
movl 0x4(%rsi), %esi
addl %esi, %eax
shlq $0x20, %rax
orq %rax, %rdx
movq %rdx, 0x28(%rsp)
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
addl %eax, %ecx
shrq $0x20, %rax
addl %esi, %eax
shlq $0x20, %rax
orq %rax, %rcx
movq %rcx, 0x58(%rsp)
movq %r13, %rdi
leaq 0x58(%rsp), %rsi
movl 0x1c(%rsp), %edx
callq 0x9666
movq %rax, 0x30(%rsp)
shrq $0x20, %rax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x48(%rsp)
leaq 0x18951(%rip), %rdi     # 0x1d858
leaq 0x30(%rsp), %r12
movq %r12, %rsi
callq 0x9986
movq %rbp, %rdi
movq %r12, %rsi
callq 0x9986
xorl %r12d, %r12d
cmpq $0x30, %r12
je 0x4f6e
movq 0x30(%rsp), %xmm1
movq (%r12,%rbx), %xmm0
paddd %xmm1, %xmm0
movd %xmm0, %eax
testl %eax, %eax
js 0x4f68
cmpl %r15d, %eax
jge 0x4f68
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
movd %xmm1, %eax
testl %eax, %eax
js 0x4f68
cmpl %r14d, %eax
jge 0x4f68
movq %xmm0, 0x28(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0xd1e2
addq $0x8, %r12
jmp 0x4f22
movsd 0x48(%rsp), %xmm0
minsd 0x10(%rsp), %xmm0
movq 0x50(%rsp), %rcx
addq $0x8, %rcx
movsd %xmm0, 0x10(%rsp)
jmp 0x4e8d
movq 0x188e3(%rip), %rax     # 0x1d878
movq 0x188e4(%rip), %rcx     # 0x1d880
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
movsd 0xd0fc(%rip), %xmm0     # 0x120a8
movq %rax, %rsi
cmpq %rcx, %rsi
je 0x506f
movslq (%rsi), %rdi
movslq 0x4(%rsi), %r8
imulq $0x18, %r8, %r9
movq (%rdx,%r9), %r10
movl (%r10,%rdi,4), %r9d
btl $0x8, %r9d
jb 0x5066
movl %r9d, %r11d
orl $0x100, %r11d           # imm = 0x100
movl %r11d, (%r10,%rdi,4)
testb %r9b, %r9b
jne 0x5066
xorl %r10d, %r10d
xorl %r9d, %r9d
cmpq $0x6, %r10
je 0x5030
movl (%rbx,%r10,8), %r11d
addl %edi, %r11d
js 0x502b
cmpl %r15d, %r11d
jge 0x502b
movl 0x4(%rbx,%r10,8), %ebp
addl %r8d, %ebp
js 0x502b
cmpl %r14d, %ebp
jge 0x502b
movl %ebp, %r12d
imulq $0x18, %r12, %r12
movl %r11d, %r11d
movq (%rdx,%r12), %r12
cmpb $0x0, (%r12,%r11,4)
jne 0x502b
btsl %r10d, %r9d
incq %r10
jmp 0x4fef
movl %r9d, %edi
andl $0x1, %edi
btl $0x1, %r9d
adcl $0x0, %edi
leal (%rdi,%rdi,2), %edi
movl %r9d, %r8d
shrl $0x3, %r8d
andl $0x1, %r8d
btl $0x2, %r9d
adcl %edi, %r8d
movsd 0x60(%rsp,%r8,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp,%r8,8)
addq $0x8, %rsi
jmp 0x4faf
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
movq %rax, %rsi
cmpq %rcx, %rsi
je 0x509c
movslq 0x4(%rsi), %rdi
imulq $0x18, %rdi, %rdi
movslq (%rsi), %r8
movq (%rdx,%rdi), %rdi
andl $0xfffffeff, (%rdi,%r8,4) # imm = 0xFFFFFEFF
addq $0x8, %rsi
jmp 0x507a
movq 0x187b5(%rip), %rdx     # 0x1d858
movq 0x187b6(%rip), %rsi     # 0x1d860
movq 0x8(%rsp), %rdi
movq (%rdi), %rdi
movq %rdx, %r8
cmpq %rsi, %r8
je 0x50d7
movslq 0x4(%r8), %r9
imulq $0x18, %r9, %r9
movslq (%r8), %r10
movq (%rdi,%r9), %r9
movl $0x1, (%r9,%r10,4)
addq $0x8, %r8
jmp 0x50b5
movq 0x8(%rsp), %rdi
movq (%rdi), %rdi
movsd 0xcfc9(%rip), %xmm0     # 0x120b0
movq %rax, %r8
cmpq %rcx, %r8
je 0x51b0
movslq (%r8), %r9
movslq 0x4(%r8), %r10
imulq $0x18, %r10, %r11
movq (%rdi,%r11), %r12
movl (%r12,%r9,4), %r11d
btl $0x8, %r11d
jb 0x51a7
movl %r11d, %ebp
orl $0x100, %ebp            # imm = 0x100
movl %ebp, (%r12,%r9,4)
testb %r11b, %r11b
jne 0x51a7
xorl %r12d, %r12d
xorl %r11d, %r11d
cmpq $0x6, %r12
je 0x516e
movl (%rbx,%r12,8), %ebp
addl %r9d, %ebp
js 0x5169
cmpl %r15d, %ebp
jge 0x5169
movl 0x4(%rbx,%r12,8), %r13d
addl %r10d, %r13d
js 0x5169
cmpl %r14d, %r13d
jge 0x5169
movl %r13d, %r13d
imulq $0x18, %r13, %r13
movl %ebp, %ebp
movq (%rdi,%r13), %r13
cmpb $0x0, (%r13,%rbp,4)
jne 0x5169
btsl %r12d, %r11d
incq %r12
jmp 0x512d
movl %r11d, %r9d
andl $0x1, %r9d
btl $0x1, %r11d
adcl $0x0, %r9d
leal (%r9,%r9,2), %r9d
movl %r11d, %r10d
shrl $0x3, %r10d
andl $0x1, %r10d
btl $0x2, %r11d
adcl %r9d, %r10d
movsd 0x60(%rsp,%r10,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp,%r10,8)
addq $0x8, %r8
jmp 0x50ea
movq 0x8(%rsp), %rdi
movq (%rdi), %rdi
cmpq %rcx, %rax
je 0x51da
movslq 0x4(%rax), %r8
imulq $0x18, %r8, %r8
movslq (%rax), %r9
movq (%rdi,%r8), %r8
andl $0xfffffeff, (%r8,%r9,4) # imm = 0xFFFFFEFF
addq $0x8, %rax
jmp 0x51b8
movq 0x8(%rsp), %rax
movq (%rax), %rax
cmpq %rsi, %rdx
je 0x5200
movslq 0x4(%rdx), %rcx
imulq $0x18, %rcx, %rcx
movslq (%rdx), %rdi
movq (%rax,%rcx), %rcx
andl $0x0, (%rcx,%rdi,4)
addq $0x8, %rdx
jmp 0x51e2
xorpd %xmm1, %xmm1
movq 0x18635(%rip), %rax     # 0x1d840
xorl %ecx, %ecx
cmpq $0x9, %rcx
je 0x5227
movsd (%rax,%rcx,8), %xmm0
mulsd 0x60(%rsp,%rcx,8), %xmm0
addsd %xmm0, %xmm1
incq %rcx
jmp 0x520d
movsd 0x10(%rsp), %xmm2
mulsd 0x48(%rax), %xmm2
cvtsi2sd %r15d, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18618(%rip), %rdi     # 0x1d870
callq 0x34e0
testl %eax, %eax
je 0x4df3
xorps %xmm0, %xmm0
movups %xmm0, 0x185e9(%rip)    # 0x1d858
andq $0x0, 0x185f1(%rip)     # 0x1d868
leaq 0x185da(%rip), %rsi     # 0x1d858
leaq 0x46fb(%rip), %rdi      # 0x9980
leaq 0x1701c(%rip), %rdx     # 0x1c2a8
callq 0x32b0
leaq 0x185d8(%rip), %rdi     # 0x1d870
callq 0x31b0
jmp 0x4df3
leaq 0x185e7(%rip), %rdi     # 0x1d890
callq 0x34e0
testl %eax, %eax
je 0x4e01
xorps %xmm0, %xmm0
movups %xmm0, 0x185b8(%rip)    # 0x1d878
andq $0x0, 0x185c0(%rip)     # 0x1d888
leaq 0x185a9(%rip), %rsi     # 0x1d878
leaq 0x46aa(%rip), %rdi      # 0x9980
leaq 0x16fcb(%rip), %rdx     # 0x1c2a8
callq 0x32b0
leaq 0x185a7(%rip), %rdi     # 0x1d890
callq 0x31b0
jmp 0x4e01