// File: smallHW89[P]gobang/GoBang_ChessBoard.cpp
// Function: ChessBoard::GetMaxValue(int, long, long)
int64_t   ChessBoard::  GetMaxValue(int deep, int64_t alpha, int64_t beta)
{
    int64_t bestVa = MM_MIN;
    std::vector<StPos>   nextList;
    int64_t va = MM_MIN;
    int win = 0;
    va = CalculateBoard(m_aiside, win, false );
    if( deep <= 0  || win )
    {
        return va;
    }
    
    int n = GetPossbilePos( m_aiside, nextList);
    for( int i=0; i<nextList.size(); i++ )
    {
        PutChess(nextList[i].x, nextList[i].y, m_aiside);
        nextList[i].score = CalculateOnePos(nextList[i].x, nextList[i].y,
                m_aiside, 0);
        UnPutChess(nextList[i].x, nextList[i].y);
    }
    sort(nextList.begin(), nextList.end(), greater<StPos>()   );    

    for( int i=0; i< nextList.size(); i++ )
    {
        StPos pos = nextList[i];
        PutChess(pos.x, pos.y, m_aiside  ); 
        win = 0; 
        va =  GetMinValue(deep-1, alpha , beta);
        UnPutChess(pos.x, pos.y);
        
        if(va  >  bestVa)  
        {
            bestVa = va;
        }
        if(va >   alpha )
            alpha = va;
        if( alpha >= beta) 
            break;
    }
    return bestVa;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq $-0x77359400, -0x30(%rbp) # imm = 0x88CA6C00
leaq -0x48(%rbp), %rdi
callq 0x4dc0
movq -0xa8(%rbp), %rax
movq $-0x77359400, -0x50(%rbp) # imm = 0x88CA6C00
movl $0x0, -0x54(%rbp)
leaq -0x54(%rbp), %rdx
xorl %ecx, %ecx
movq %rax, %rdi
movsbl 0x198(%rax), %esi
callq 0x3b90
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x48a1
cmpl $0x0, -0x54(%rbp)
je 0x48b5
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x58(%rbp)
jmp 0x4b68
movq -0xa8(%rbp), %rdi
movsbl 0x198(%rdi), %esi
leaq -0x48(%rbp), %rdx
callq 0x3780
movl %eax, -0xac(%rbp)
jmp 0x48d4
movl -0xac(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x70(%rbp)
movslq -0x70(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4ec0
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
jae 0x4a1a
movslq -0x70(%rbp), %rsi
leaq -0x48(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x4ef0
movq -0xc8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xbc(%rbp)
movslq -0x70(%rbp), %rsi
callq 0x4ef0
movq -0xa8(%rbp), %rdi
movl -0xbc(%rbp), %esi
movl 0x4(%rax), %edx
movsbl 0x198(%rdi), %ecx
callq 0x12e0
jmp 0x4955
movslq -0x70(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x4ef0
movl (%rax), %eax
movl %eax, -0xdc(%rbp)
movslq -0x70(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x4ef0
movl -0xdc(%rbp), %esi
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movl 0x4(%rcx), %edx
xorl %r8d, %r8d
movq %rax, %rdi
movsbl 0x198(%rax), %ecx
callq 0x3940
movq %rax, -0xd8(%rbp)
movslq -0x70(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x4ef0
movq -0xd8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movslq -0x70(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x4ef0
movl (%rax), %eax
movl %eax, -0xcc(%rbp)
movslq -0x70(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x4ef0
movq -0xa8(%rbp), %rdi
movl -0xcc(%rbp), %esi
movl 0x4(%rax), %edx
callq 0x1360
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x48e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4fd0
jmp 0x4b7e
leaq -0x48(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x4f50
movq -0xe8(%rbp), %rdi
movq %rax, -0x78(%rbp)
callq 0x4f80
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x4f10
jmp 0x4a4d
movl $0x0, -0x88(%rbp)
movslq -0x88(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4ec0
movq %rax, %rcx
movq -0xf0(%rbp), %rax
cmpq %rcx, %rax
jae 0x4b59
movslq -0x88(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x4ef0
movq -0xa8(%rbp), %rdi
movq 0x10(%rax), %rcx
movq %rcx, -0x90(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0xa0(%rbp)
movl -0xa0(%rbp), %esi
movl -0x9c(%rbp), %edx
movsbl 0x198(%rdi), %ecx
callq 0x12e0
jmp 0x4ac7
movq -0xa8(%rbp), %rdi
movl $0x0, -0x54(%rbp)
movl -0x14(%rbp), %esi
decl %esi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x44d0
movq %rax, -0xf8(%rbp)
jmp 0x4af0
movq -0xa8(%rbp), %rdi
movq -0xf8(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0xa0(%rbp), %esi
movl -0x9c(%rbp), %edx
callq 0x1360
movq -0x50(%rbp), %rax
cmpq -0x30(%rbp), %rax
jle 0x4b25
movq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x20(%rbp), %rax
jle 0x4b37
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jl 0x4b43
jmp 0x4b59
jmp 0x4b45
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x4a57
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x58(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4fd0
movq -0x8(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x10f0
nopw (%rax,%rax)