// File: smallHW89[P]gobang/GoBang_ChessBoard.cpp
// Function: ChessBoard::GetMinValue(int, long, long)
int64_t   ChessBoard::  GetMinValue(int deep, int64_t alpha, int64_t  beta)
{
    int64_t bestVa = MM_MAX;
    std::vector<StPos>   nextList;
    int64_t va = MM_MAX;
    int win = 0;
    va = CalculateBoard(m_aiside, win , true);
    if( deep <= 0  || win )
    {
        return va;
    }
    
    int n = GetPossbilePos( m_otherside, nextList);
    for( int i=0; i<nextList.size(); i++ )
    {
        PutChess(nextList[i].x, nextList[i].y , m_otherside);
        nextList[i].score = CalculateOnePos(nextList[i].x, nextList[i].y,
                m_otherside, 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_otherside  ); 
        win = 0; 
        va =  GetMaxValue(deep-1, alpha, beta);
        UnPutChess(pos.x, pos.y);
        
        if(va  <  bestVa)  
        {
            bestVa = va;
        }
        if(va <   beta )
            beta = 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 = 0x77359400
leaq -0x48(%rbp), %rdi
callq 0x4dc0
movq -0xa8(%rbp), %rax
movq $0x77359400, -0x50(%rbp) # imm = 0x77359400
movl $0x0, -0x54(%rbp)
leaq -0x54(%rbp), %rdx
movl $0x1, %ecx
movq %rax, %rdi
movsbl 0x198(%rax), %esi
callq 0x3b90
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x4544
cmpl $0x0, -0x54(%rbp)
je 0x4558
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x58(%rbp)
jmp 0x480b
movq -0xa8(%rbp), %rdi
movsbl 0x199(%rdi), %esi
leaq -0x48(%rbp), %rdx
callq 0x3780
movl %eax, -0xac(%rbp)
jmp 0x4577
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 0x46bd
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 0x199(%rdi), %ecx
callq 0x12e0
jmp 0x45f8
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 0x199(%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 0x4587
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4fd0
jmp 0x4821
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 0x46f0
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 0x47fc
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 0x199(%rdi), %ecx
callq 0x12e0
jmp 0x476a
movq -0xa8(%rbp), %rdi
movl $0x0, -0x54(%rbp)
movl -0x14(%rbp), %esi
decl %esi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x4830
movq %rax, -0xf8(%rbp)
jmp 0x4793
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
jge 0x47c8
movq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x47da
movq -0x50(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jl 0x47e6
jmp 0x47fc
jmp 0x47e8
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x46fa
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)