// File: smallHW89[P]gobang/GoBang_ChessBoard.cpp
// Function: ChessBoard::CalculateOnePos(int, int, char, int)
int64_t ChessBoard::CalculateOnePos(int x, int y , ChessSide side, int flag )
{
    BoardType  res[4]={0};
    res[0] = CalculatePosHeng(x, y, side);
    res[1] = CalculatePosShu(x,y, side);
    res[2] = CalculatePosLeft(x, y, side);
    res[3] = CalculatePosRight(x, y, side);
    //printf("CaluatOne pos(%u %u)  %u \n", x, y , res[0]);
    //printf("CaluatOne pos(%u %u)  %u \n", x, y , res[1]);
    //printf("CaluatOne pos(%u %u)  %u \n", x, y , res[2]);
    //printf("CaluatOne pos(%u %u)  %u \n", x, y , res[3]);
    //memset(m_bType, 0 , sizeof(m_bType));
    //memset(m_wType, 0 , sizeof(m_wType));


    int xx = x - (1+m_size)/2;
    int yy = y - (1+m_size)/2; 
    if(xx<0 ) xx = -xx;
    if(yy<0 ) yy = -yy;
    int dist = (xx>yy )? xx:yy;


    int64_t score =   ScoreList[res[0]] + ScoreList[res[1]] + ScoreList[res[2]] 
        + ScoreList[res[3]];
    if(flag != 0 )
    {
        if(side == Chess_Black )
        {
            m_bType[res[0]] ++;
            m_bType[res[1]] ++;
            m_bType[res[2]] ++;
            m_bType[res[3]] ++;

        }
        if(side == Chess_White )
        {
            m_wType[res[0]] ++;
            m_wType[res[1]] ++;
            m_wType[res[2]] ++;
            m_wType[res[3]] ++;

        }
    }

    return score + (1+m_size)/2 - dist;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl %r8d, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1090
movq -0x58(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movsbl -0x11(%rbp), %ecx
callq 0x32b0
movq -0x58(%rbp), %rdi
movl %eax, -0x30(%rbp)
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movsbl -0x11(%rbp), %ecx
callq 0x3350
movq -0x58(%rbp), %rdi
movl %eax, -0x2c(%rbp)
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movsbl -0x11(%rbp), %ecx
callq 0x3430
movq -0x58(%rbp), %rdi
movl %eax, -0x28(%rbp)
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movsbl -0x11(%rbp), %ecx
callq 0x35c0
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, -0x24(%rbp)
movl -0xc(%rbp), %ecx
movl 0x194(%rax), %eax
addl $0x1, %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0x58(%rbp), %rax
subl %edx, %ecx
movl %ecx, -0x34(%rbp)
movl -0x10(%rbp), %ecx
movl %ecx, -0x4c(%rbp)
movl 0x194(%rax), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x3a1f
xorl %eax, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x38(%rbp)
jge 0x3a2d
xorl %eax, %eax
subl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x3a3d
movl -0x34(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0x3a43
movl -0x38(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movslq -0x30(%rbp), %rcx
leaq 0x763c(%rip), %rax      # 0xb090
movl (%rax,%rcx,4), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x762e(%rip), %rcx      # 0xb090
addl (%rcx,%rdx,4), %eax
movslq -0x28(%rbp), %rdx
leaq 0x7620(%rip), %rcx      # 0xb090
addl (%rcx,%rdx,4), %eax
movslq -0x24(%rbp), %rdx
leaq 0x7612(%rip), %rcx      # 0xb090
addl (%rcx,%rdx,4), %eax
cltq
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x3b55
movsbl -0x11(%rbp), %eax
cmpl $0x62, %eax
jne 0x3af2
movq -0x58(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl 0x19c(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x19c(%rax,%rcx,4)
movslq -0x2c(%rbp), %rcx
movl 0x19c(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x19c(%rax,%rcx,4)
movslq -0x28(%rbp), %rcx
movl 0x19c(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x19c(%rax,%rcx,4)
movslq -0x24(%rbp), %rcx
movl 0x19c(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x19c(%rax,%rcx,4)
movsbl -0x11(%rbp), %eax
cmpl $0x77, %eax
jne 0x3b53
movq -0x58(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl 0x1ec(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x1ec(%rax,%rcx,4)
movslq -0x2c(%rbp), %rcx
movl 0x1ec(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x1ec(%rax,%rcx,4)
movslq -0x28(%rbp), %rcx
movl 0x1ec(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x1ec(%rax,%rcx,4)
movslq -0x24(%rbp), %rcx
movl 0x1ec(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x1ec(%rax,%rcx,4)
jmp 0x3b55
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movl 0x194(%rax), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x68(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movslq -0x3c(%rbp), %rcx
subq %rcx, %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)