// File: /workspace/github_cpp_makefile_star2_O2/syky27[P]TicTacToe/src/DNRemoteHumanPlayer.cpp
// Function: DNRemoteHumanPlayer::triggerTurn(int, int)
bool DNRemoteHumanPlayer::triggerTurn(int y, int x)
{
    sleep(2);
    if(!amIServer){ DNWindow::getInstance().drawHeaderWithGuide(string("TicTacToe press 'x' to trigger turn ==> WAIT")); processOponentsTurn();}
    else {DNWindow::getInstance().drawHeaderWithGuide(string("TicTacToe press 'x' to trigger turn ==> PLAY"));}
    
    char ch;
    int key;
    while ((key = getch())) {
        ch = key;
        if (key == KEY_UP) {
            DNWindow::getInstance().moveUp();
            continue;

        }
        if (key == KEY_DOWN) {
            DNWindow::getInstance().moveDown();
            continue;
        }
        if (key == KEY_LEFT) {
            DNWindow::getInstance().moveLeft();
            continue;
        }

        if (key == KEY_RIGHT) {
            DNWindow::getInstance().moveRight();
            continue;
        }


        if (ch == 'q' || ch == 'Q') {
            transferQuitGame();
        }


        if (ch == 'x') {
            int x = 0;
            int y = 0;
            DNCellState state;

            DNWindow::getInstance().getCursorPosition(x, y);
            if (this->game_map->recordMove(this->getSymbol(), x - 0, y - 3, state)) {
                DNWindow::getInstance().drawSymbol(this->getSymbol(), y, x);
                this->game_map->debugToFile();
                transferTurn(y, x);


                if (state != EMPTY) {
                    if (state == this->getSymbol()) {
                        string you_winner("YOU are WINNER!!!");
                        DNWindow::getInstance().terminateWithErrorMessage(you_winner);
                    }

                }
                DNWindow::getInstance().drawHeaderWithGuide(string("TicTacToe press 'x' to trigger turn ==> WAIT"));
                processOponentsTurn();
                DNWindow::getInstance().drawHeaderWithGuide(string("TicTacToe press 'x' to trigger turn ==> PLAY"));

            }
            else {
                DNWindow::getInstance().sound();
                DNWindow::getInstance().sound();
            }


            if (ch == 'q') {
                DNWindow::getInstance().terminate();
            }
        }
    }
    return true;



}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %rbx
pushq $0x2
popq %rdi
callq 0x3220
movq %rbx, 0x18(%rsp)
movb 0x50(%rbx), %bpl
callq 0x381e
movq %rax, %r14
testb %bpl, %bpl
je 0x568b
leaq 0x2cf4(%rip), %rsi      # 0x8357
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x3c1e
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x6660
leaq 0x48(%rsp), %rdi
callq 0x3170
jmp 0x56c2
leaq 0x2c98(%rip), %rsi      # 0x832a
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x3c1e
leaq 0x68(%rsp), %rsi
movq %r14, %rdi
callq 0x6660
leaq 0x68(%rsp), %rdi
callq 0x3170
movq 0x18(%rsp), %rdi
callq 0x597a
movq 0x6907(%rip), %r15      # 0xbfd0
leaq 0x10(%rsp), %r14
leaq 0xc(%rsp), %r12
leaq 0x2c2a(%rip), %rbp      # 0x8304
movq (%r15), %rdi
callq 0x3120
leal -0x102(%rax), %ecx
cmpl $0x3, %ecx
ja 0x5706
movslq (%rbp,%rcx,4), %rax
addq %rbp, %rax
jmpq *%rax
callq 0x381e
movq %rax, %rdi
callq 0x6b90
jmp 0x56da
testl %eax, %eax
je 0x5903
cmpb $0x51, %al
je 0x571f
movzbl %al, %eax
cmpl $0x78, %eax
je 0x5758
cmpl $0x71, %eax
jne 0x56da
movq 0x18(%rsp), %rdi
callq 0x5c2a
jmp 0x56da
callq 0x381e
movq %rax, %rdi
callq 0x6bbc
jmp 0x56da
callq 0x381e
movq %rax, %rdi
callq 0x6bea
jmp 0x56da
callq 0x381e
movq %rax, %rdi
callq 0x6b62
jmp 0x56da
andl $0x0, 0x10(%rsp)
andl $0x0, 0xc(%rsp)
callq 0x381e
movq %rax, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x7696
movq 0x18(%rsp), %rbx
movq 0x48(%rbx), %r13
movq %rbx, %rdi
callq 0x557c
movl 0x10(%rsp), %edx
movl 0xc(%rsp), %ecx
addl $-0x3, %ecx
movq %r13, %rdi
movl %eax, %esi
leaq 0x24(%rsp), %r8
callq 0x4a92
movq %r14, %r15
movl %eax, %r14d
callq 0x381e
movq %rax, %r13
testb %r14b, %r14b
je 0x58df
movq %rbx, %rdi
callq 0x557c
movq %r13, %rdi
movl %eax, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0x7762
movq 0x48(%rbx), %rdi
callq 0x477c
movl 0xc(%rsp), %esi
movl 0x10(%rsp), %edx
movq %rbx, %rdi
callq 0x5ce4
movl 0x24(%rsp), %r14d
testl %r14d, %r14d
movq 0x67d9(%rip), %r15      # 0xbfd0
je 0x5858
movq 0x18(%rsp), %rdi
callq 0x557c
cmpl %eax, %r14d
jne 0x5858
leaq 0x28(%rsp), %rdi
leaq 0x2b70(%rip), %rsi      # 0x8384
leaq 0x17(%rsp), %rdx
callq 0x3c1e
callq 0x381e
leaq 0xc8(%rsp), %rbx
movq %rax, %r13
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
callq 0x33f0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x7060
movq %rbx, %rdi
callq 0x3170
leaq 0x28(%rsp), %rdi
callq 0x3170
callq 0x381e
movq %rax, %r13
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
leaq 0x2ab8(%rip), %rsi      # 0x832a
leaq 0x28(%rsp), %rdx
callq 0x3c1e
movq %r13, %rdi
movq %r14, %rsi
callq 0x6660
movq %r14, %rdi
leaq 0x10(%rsp), %r14
leaq 0xc(%rsp), %r12
callq 0x3170
movq 0x18(%rsp), %rdi
callq 0x597a
callq 0x381e
movq %rax, %rbx
leaq 0x88(%rsp), %r13
movq %r13, %rdi
leaq 0x2a9a(%rip), %rsi      # 0x8357
leaq 0x28(%rsp), %rdx
callq 0x3c1e
movq %rbx, %rdi
movq %r13, %rsi
callq 0x6660
movq %r13, %rdi
callq 0x3170
jmp 0x56da
movq %r13, %rdi
callq 0x7850
callq 0x381e
movq %rax, %rdi
callq 0x7850
movq %r15, %r14
movq 0x66d2(%rip), %r15      # 0xbfd0
jmp 0x56da
movb $0x1, %al
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x5967
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x5967
jmp 0x596e
jmp 0x596e
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x3170
jmp 0x5946
jmp 0x596e
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x5967
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x5967
jmp 0x596e
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3170
jmp 0x5971
movq %rax, %rbx
movq %rbx, %rdi
callq 0x34d0
nop