// File: /workspace/github_cpp_makefile_star2_O1/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 0x2dce
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 0x2c02
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 0x2d6b
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 0x2e5b
cmpb $0x62, %r8b
setne %dl
orb %dil, %dl
je 0x2e93
cmpb $0x77, %r8b
setne %dl
orb %cl, %dl
je 0x2ede
cmpb $0x77, %r8b
setne %cl
orb %dil, %cl
jne 0x2ecf
cmpl $0x0, 0x1a0(%r14)
jg 0x2ebb
cmpl $0x0, 0x1a4(%r14)
jle 0x2ec1
cmpl $0x0, 0x1f4(%r14)
jne 0x2ec1
cmpl $0x0, 0x1f8(%r14)
je 0x2ebb
jmp 0x2ec1
cmpl $0x0, 0x1a0(%r14)
jg 0x2e83
cmpl $0x0, 0x1a4(%r14)
jle 0x2e89
cmpl $0x0, 0x1f4(%r14)
jne 0x2e89
cmpl $0x0, 0x1f8(%r14)
jne 0x2e89
movl $0x1, (%rsi)
cmpl $0x1, (%rsi)
movl $0x77359400, %ecx       # imm = 0x77359400
jmp 0x2ecb
cmpl $0x0, 0x1f0(%r14)
jg 0x2ebb
cmpl $0x0, 0x1f4(%r14)
jle 0x2ec1
cmpl $0x0, 0x1a4(%r14)
jne 0x2ec1
cmpl $0x0, 0x1a8(%r14)
jne 0x2ec1
movl $0x1, (%rsi)
cmpl $0x1, (%rsi)
movq $-0x77359400, %rcx      # imm = 0x88CA6C00
cmoveq %rcx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x1f0(%r14)
jle 0x2eee
movl $0x1, (%rsi)
cmpl $0x0, 0x1f4(%r14)
jle 0x2ecf
cmpl $0x0, 0x1a4(%r14)
jne 0x2ecf
cmpl $0x0, 0x1a8(%r14)
jne 0x2ecf
movl $0x1, (%rsi)
jmp 0x2ecf