// File: smallHW89[P]gobang/GoBang_ChessBoard.cpp
// Function: ChessBoard::PutHumenChessGetAI(StPos&, StPos&)
int ChessBoard:: PutHumenChessGetAI(StPos &humPos, StPos &aiPos)
{
    if( m_aiside == Chess_Black   && m_stepnum == 0 )
    {
        aiPos.x = (1+m_size)/2;
        aiPos.y = (1+m_size)/2;
        return 0;
    }
    else if( m_aiside == Chess_White && m_stepnum == 0 )
    {
        PutChess(humPos.x, humPos.y, Chess_Black);

        int x ,y;
        x = y = (1+m_size)/2;
        int k = random()%8; 
        if( k==0 ){
            aiPos.x = x-1;   aiPos.y = y-1;
        }
        if(k==1){
            aiPos.x = x-1;   aiPos.y = y ;
        }
        if(k==2){
            aiPos.x = x-1;   aiPos.y = y+1;
        }
        if(k==3){
            aiPos.x = x ;  aiPos.y = y-1;
        }
        if(k==4){
            aiPos.x = x ; aiPos.y = y+1 ;
        }
        if(k==5){
            aiPos.x = x+1; aiPos.y = y-1;
        }
        if(k==6){
            aiPos.x = x+1; aiPos.y = y;
        }
        if(k==7){
            aiPos.x = x+1; aiPos.y =  y+1;
        }
        return 0;
    }

    PutChess(humPos.x, humPos.y, m_otherside);
    
    int ret = GetNextPosMinMax(2, aiPos,MM_MIN, MM_MAX );
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movsbl 0x198(%rax), %eax
cmpl $0x62, %eax
jne 0x4c08
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x4c08
movq -0x38(%rbp), %rax
movl 0x194(%rax), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %edx
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movl %edx, (%rcx)
movl 0x194(%rax), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x4db3
movq -0x38(%rbp), %rax
movsbl 0x198(%rax), %eax
cmpl $0x77, %eax
jne 0x4d68
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x4d68
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x62, %ecx
callq 0x12e0
movq -0x38(%rbp), %rax
movl 0x194(%rax), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x28(%rbp)
movl %eax, -0x24(%rbp)
callq 0x1070
movl $0x8, %ecx
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x4c92
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x1, -0x2c(%rbp)
jne 0x4cae
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x2, -0x2c(%rbp)
jne 0x4ccd
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x3, -0x2c(%rbp)
jne 0x4ce9
movl -0x24(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x4, -0x2c(%rbp)
jne 0x4d05
movl -0x24(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x5, -0x2c(%rbp)
jne 0x4d24
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x6, -0x2c(%rbp)
jne 0x4d40
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x7, -0x2c(%rbp)
jne 0x4d5f
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x4db3
jmp 0x4d6a
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %esi
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %edx
movq %rax, %rdi
movsbl 0x199(%rax), %ecx
callq 0x12e0
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x2, %esi
movq $-0x77359400, %rcx      # imm = 0x88CA6C00
movl $0x77359400, %r8d       # imm = 0x77359400
callq 0x3ed0
movl %eax, -0x30(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)