// File: /workspace/github_cpp_makefile_star2_O3/smallHW89[P]gobang/GoBang_ChessBoard.cpp
// Function: ChessBoard::CalculateBoard(char, int&, bool)
int64_t ChessBoard::CalculateBoard( ChessSide side , int &win, bool isMax)
{
    int  blackWin=0, whiteWin=0, blackScore=0, whiteScore=0; 
    memset(m_bType, 0 , sizeof(m_bType));
    memset(m_wType, 0 , sizeof(m_wType));

    for(int i=0; i<m_chessList.size(); i++ ) 
    {
        int t = CalculateOnePos(m_chessList[i].x, m_chessList[i].y,
                m_chessList[i].side, 1);                    

        if( Chess_Black ==  m_chessList[i].side )
        {
            blackScore += t;
        }
        else
        {
            whiteScore += t;
        }
    }     

    int64_t  score;
    if( side == Chess_Black )
        score = blackScore - whiteScore;
    else
        score = whiteScore - blackScore;

    win = 0;
    if( side == Chess_Black  && isMax) //这里是AI下子后
    {
        if(m_bType[Board_FIVE] > 0  ) 
            win = 1; 
        else if(m_bType[Board_FOUR] > 0   &&
                m_wType[Board_FOUR]==0  && m_wType[Board_SFOUR] == 0 ) 
            win = 1;
        if(win == 1)
            score =  MM_MAX;
    }
    else if( side == Chess_Black &&  !isMax ) //对方下完后
    {
        if(m_wType[Board_FIVE] >0     ) 
            win =1;
        else if(m_wType[Board_FOUR] >0  &&
                m_bType[Board_FOUR] ==0 && m_bType[Board_SFOUR] ==0 ) 
            win = 1;
        if(win == 1)
            score = MM_MIN;
    }
    else if(side == Chess_White  && isMax) //AI白，AI下子后
    {
        if(m_wType[Board_FIVE ]> 0 ) 
            win = 1;
        if(m_wType[Board_FOUR] > 0   &&
                m_bType[Board_FOUR]==0  && m_bType[Board_SFOUR] == 0 ) 
            win = 1;
        if(win==1  )
            score == MM_MAX;
    }
    else if(side == Chess_White && !isMax)
    {
         if(m_bType[Board_FIVE] > 0  ) 
            win = 1; 
        else if(m_bType[Board_FOUR] > 0   &&
                m_wType[Board_FOUR]==0  && m_wType[Board_SFOUR] == 0 ) 
            win = 1;
        if(win == 1)
            score =  MM_MIN;
    }
    return score;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movl %esi, -0x2c(%rbp)
movq %rdi, %r14
addq $0x19c, %rdi            # imm = 0x19C
xorl %r13d, %r13d
movl $0xa0, %edx
xorl %esi, %esi
callq 0x1070
movq 0x240(%r14), %rcx
movl $0x0, %ebx
cmpq %rcx, 0x248(%r14)
je 0x2d74
movl $0x10, %r12d
xorl %r15d, %r15d
xorl %ebx, %ebx
xorl %r13d, %r13d
movl -0x10(%rcx,%r12), %esi
movl -0xc(%rcx,%r12), %edx
movsbl (%rcx,%r12), %ecx
movq %r14, %rdi
movl $0x1, %r8d
callq 0x2ba8
movq 0x240(%r14), %rcx
movq 0x248(%r14), %rdx
cmpb $0x62, (%rcx,%r12)
movl %eax, %esi
movl $0x0, %edi
cmovel %edi, %esi
cmovnel %edi, %eax
addl %esi, %r13d
addl %eax, %ebx
incq %r15
subq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
addq $0x18, %r12
cmpq %r15, %rdx
ja 0x2d11
movl %ebx, %eax
subl %r13d, %eax
subl %ebx, %r13d
movl -0x2c(%rbp), %r8d
cmpb $0x62, %r8b
setne %dl
cmovel %eax, %r13d
movslq %r13d, %rax
movq -0x38(%rbp), %rsi
movl $0x0, (%rsi)
movl -0x30(%rbp), %edi
movl %edi, %ecx
xorb $0x1, %cl
orb %cl, %dl
je 0x2dd8
cmpb $0x62, %r8b
setne %dl
orb %dil, %dl
je 0x2e0f
cmpb $0x77, %r8b
setne %dl
orb %cl, %dl
je 0x2e40
cmpb $0x77, %r8b
setne %cl
orb %dil, %cl
jne 0x2e7a
movq $-0x77359400, %rcx      # imm = 0x88CA6C00
jmp 0x2ddd
movl $0x77359400, %ecx       # imm = 0x77359400
cmpl $0x0, 0x1a0(%r14)
jg 0x2e71
cmpl $0x0, 0x1a4(%r14)
jle 0x2e7a
cmpl $0x0, 0x1f4(%r14)
jne 0x2e7a
cmpl $0x0, 0x1f8(%r14)
je 0x2e71
jmp 0x2e7a
movq $-0x77359400, %rcx      # imm = 0x88CA6C00
cmpl $0x0, 0x1f0(%r14)
jg 0x2e71
cmpl $0x0, 0x1f4(%r14)
jle 0x2e7a
cmpl $0x0, 0x1a4(%r14)
jne 0x2e7a
cmpl $0x0, 0x1a8(%r14)
je 0x2e71
jmp 0x2e7a
cmpl $0x0, 0x1f0(%r14)
jle 0x2e50
movl $0x1, (%rsi)
cmpl $0x0, 0x1f4(%r14)
jle 0x2e7a
cmpl $0x0, 0x1a4(%r14)
jne 0x2e7a
cmpl $0x0, 0x1a8(%r14)
movq %rax, %rcx
jne 0x2e7a
movl $0x1, (%rsi)
movq %rcx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop