// File: 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
subq $0x60, %rsp
movb %cl, %al
movb %sil, %cl
movq %rdi, -0x8(%rbp)
movb %cl, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x48(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
addq $0x19c, %rdi            # imm = 0x19C
xorl %esi, %esi
movl $0x50, %edx
callq 0x1090
movq -0x48(%rbp), %rdi
addq $0x1ec, %rdi            # imm = 0x1EC
xorl %esi, %esi
movl $0x50, %edx
callq 0x1090
movl $0x0, -0x30(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
addq $0x240, %rdi            # imm = 0x240
callq 0x4ec0
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jae 0x3cd2
movq -0x48(%rbp), %rdi
addq $0x240, %rdi            # imm = 0x240
movslq -0x30(%rbp), %rsi
callq 0x4ef0
movq -0x48(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x58(%rbp)
addq $0x240, %rdi            # imm = 0x240
movslq -0x30(%rbp), %rsi
callq 0x4ef0
movq -0x48(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0x54(%rbp)
addq $0x240, %rdi            # imm = 0x240
movslq -0x30(%rbp), %rsi
callq 0x4ef0
movl -0x58(%rbp), %esi
movl -0x54(%rbp), %edx
movq -0x48(%rbp), %rdi
movl $0x1, %r8d
movsbl 0x10(%rax), %ecx
callq 0x3940
movq -0x48(%rbp), %rdi
movl %eax, -0x34(%rbp)
addq $0x240, %rdi            # imm = 0x240
movslq -0x30(%rbp), %rsi
callq 0x4ef0
movsbl 0x10(%rax), %ecx
movl $0x62, %eax
cmpl %ecx, %eax
jne 0x3cb9
movl -0x34(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x3cc2
movl -0x34(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x3cc4
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3c02
movsbl -0x9(%rbp), %eax
cmpl $0x62, %eax
jne 0x3ce9
movl -0x28(%rbp), %eax
subl -0x2c(%rbp), %eax
cltq
movq %rax, -0x40(%rbp)
jmp 0x3cf5
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movsbl -0x9(%rbp), %eax
cmpl $0x62, %eax
jne 0x3d70
testb $0x1, -0x19(%rbp)
je 0x3d70
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1a0(%rax)
jle 0x3d27
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x3d5a
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1a4(%rax)
jle 0x3d58
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1f4(%rax)
jne 0x3d58
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1f8(%rax)
jne 0x3d58
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x3d5a
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x3d6b
movq $0x77359400, -0x40(%rbp) # imm = 0x77359400
jmp 0x3eb7
movsbl -0x9(%rbp), %eax
cmpl $0x62, %eax
jne 0x3de1
testb $0x1, -0x19(%rbp)
jne 0x3de1
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1f0(%rax)
jle 0x3d98
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x3dcb
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1f4(%rax)
jle 0x3dc9
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1a4(%rax)
jne 0x3dc9
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1a8(%rax)
jne 0x3dc9
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x3dcb
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x3ddc
movq $-0x77359400, -0x40(%rbp) # imm = 0x88CA6C00
jmp 0x3eb5
movsbl -0x9(%rbp), %eax
cmpl $0x77, %eax
jne 0x3e43
testb $0x1, -0x19(%rbp)
je 0x3e43
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1f0(%rax)
jle 0x3e07
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1f4(%rax)
jle 0x3e38
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1a4(%rax)
jne 0x3e38
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1a8(%rax)
jne 0x3e38
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x3e41
jmp 0x3eb3
movsbl -0x9(%rbp), %eax
cmpl $0x77, %eax
jne 0x3eb1
testb $0x1, -0x19(%rbp)
jne 0x3eb1
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1a0(%rax)
jle 0x3e6b
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x3e9e
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1a4(%rax)
jle 0x3e9c
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1f4(%rax)
jne 0x3e9c
movq -0x48(%rbp), %rax
cmpl $0x0, 0x1f8(%rax)
jne 0x3e9c
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x3e9e
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x3eaf
movq $-0x77359400, -0x40(%rbp) # imm = 0x88CA6C00
jmp 0x3eb1
jmp 0x3eb3
jmp 0x3eb5
jmp 0x3eb7
movq -0x40(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)