// File: nesro[P]NCursesGomoku/src/client.cpp
// Function: CClient::nextMove()
void CClient::nextMove(void) {
    
    static bool firstMove = true;

    int sendSize;
    char sendData[4];
    memset(sendData, '\0', 4);

    int recvSize;
    char recvData[4];
    memset(recvData, '\0', 4);

    char message[CBoard::MESSAGE_LENGTH];

    /* if this is the first move of the client, he can not send the data about
     * the local player move, because he don't play yet. */
    if (firstMove == false) {

        /* prepare send data */
        if (m_Game->m_Players[0]->m_Surrender) {
            sendData[2] = (char) 1;
        } else {
            sendData[0] = (char) m_Board->m_LastStone.m_X;
            sendData[1] = (char) m_Board->m_LastStone.m_Y;
        }

        /* send */
        m_Board->printMessage(" Client sending informations.");
        usleep(500000);

        if ((sendSize = send(m_Game->m_ConnectionSocket, sendData, 4, 0)) ==
                -1) {
            throw CNetworkException("Fatal network error: Client send failed.");
        }

    } else {
        firstMove = false;
    }

    /* nothing to do here */
    if (m_Game->m_Players[0]->m_Surrender || m_IsWinner == true) {
        return;
    }

    /* recv */
    m_Board->printMessage(" Client waits for server move.");
    usleep(500000);

    if ((recvSize = recv(m_Game->m_ConnectionSocket, recvData, 4, 0)) == -1) {
        throw CNetworkException("Fatal network error: Client recv failed.");
    }

    /* parse */
    memset(message, 0, CBoard::MESSAGE_LENGTH);
    sprintf(message, " Client received: %d,%d,%d", recvData[0],
            recvData[1], recvData[2]);
    m_Board->printMessage(message);

    usleep(500000);

    if (recvData[2] == 1) {
        m_Surrender = true;
        return;
    }

    if (m_Board->addStone(m_Mark, (int) recvData[1], (int) recvData[0]) ==
            false) {
        throw CNetworkException("Fatal network error: Bad data received.");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x3180
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x3180
movb 0x71d6(%rip), %al       # 0xc260
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x515e
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x40(%rax), %rax
testb $0x1, 0x8(%rax)
je 0x50b0
movb $0x1, -0xe(%rbp)
jmp 0x50c8
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rcx
movl 0x28(%rcx), %ecx
movb %cl, -0x10(%rbp)
movq 0x10(%rax), %rax
movl 0x2c(%rax), %eax
movb %al, -0xf(%rbp)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x383c(%rip), %rsi      # 0x8913
callq 0x4d00
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x3390
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movl 0xc(%rax), %edi
leaq -0x10(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x3170
movl %eax, -0xc(%rbp)
cmpl $-0x1, %eax
jne 0x515c
movl $0x28, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
leaq 0x380d(%rip), %rsi      # 0x8931
callq 0x6480
jmp 0x512b
movq -0x60(%rbp), %rdi
leaq 0x6b8a(%rip), %rsi      # 0xbcc0
leaq 0x13e3(%rip), %rdx      # 0x6520
callq 0x3400
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x31d0
jmp 0x52f9
jmp 0x5165
movb $0x0, 0x70fb(%rip)      # 0xc260
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x40(%rax), %rax
testb $0x1, 0x8(%rax)
jne 0x5188
movq -0x58(%rbp), %rax
movb 0xa(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x518d
jmp 0x52f3
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x37be(%rip), %rsi      # 0x895a
callq 0x4d00
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x3390
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movl 0xc(%rax), %edi
leaq -0x18(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x30f0
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
jne 0x5221
movl $0x28, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x68(%rbp)
leaq 0x3790(%rip), %rsi      # 0x8979
callq 0x6480
jmp 0x51f0
movq -0x68(%rbp), %rdi
leaq 0x6ac5(%rip), %rsi      # 0xbcc0
leaq 0x131e(%rip), %rdx      # 0x6520
callq 0x3400
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x31d0
jmp 0x52f9
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x3180
leaq -0x40(%rbp), %rdi
movsbl -0x18(%rbp), %edx
movsbl -0x17(%rbp), %ecx
movsbl -0x16(%rbp), %r8d
leaq 0x3759(%rip), %rsi      # 0x89a2
movb $0x0, %al
callq 0x3080
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4d00
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x3390
movsbl -0x16(%rbp), %eax
cmpl $0x1, %eax
jne 0x527e
movq -0x58(%rbp), %rax
movb $0x1, 0x8(%rax)
jmp 0x52f3
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rdi
movb 0x9(%rax), %al
movsbl -0x17(%rbp), %edx
movsbl -0x18(%rbp), %ecx
movsbl %al, %esi
callq 0x4590
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x52f3
movl $0x28, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
leaq 0x36ff(%rip), %rsi      # 0x89bd
callq 0x6480
jmp 0x52c5
movq -0x70(%rbp), %rdi
leaq 0x69f0(%rip), %rsi      # 0xbcc0
leaq 0x1249(%rip), %rdx      # 0x6520
callq 0x3400
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x31d0
jmp 0x52f9
addq $0x70, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3410
nopw %cs:(%rax,%rax)
nopl (%rax)