// File: 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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x120(%rbp)
movl $0x2, %edi
callq 0x32a0
movq -0x120(%rbp), %rax
testb $0x1, 0x50(%rax)
jne 0x73e6
callq 0x3a90
movq %rax, -0x130(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x35e0
movq -0x128(%rbp), %rdx
leaq 0x4feb(%rip), %rsi      # 0xc360
leaq -0x30(%rbp), %rdi
callq 0x42f0
jmp 0x7380
movq -0x130(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x9d00
jmp 0x7392
leaq -0x30(%rbp), %rdi
callq 0x3200
leaq -0x31(%rbp), %rdi
callq 0x3400
movq -0x120(%rbp), %rdi
callq 0x7880
jmp 0x7472
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x73d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3200
leaq -0x31(%rbp), %rdi
callq 0x3400
jmp 0x7873
callq 0x3a90
movq %rax, -0x140(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x35e0
movq -0x138(%rbp), %rdx
leaq 0x4f7d(%rip), %rsi      # 0xc38d
leaq -0x68(%rbp), %rdi
callq 0x42f0
jmp 0x741b
movq -0x140(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x9d00
jmp 0x742d
leaq -0x68(%rbp), %rdi
callq 0x3200
leaq -0x69(%rbp), %rdi
callq 0x3400
jmp 0x7472
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7464
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3200
leaq -0x69(%rbp), %rdi
callq 0x3400
jmp 0x7873
jmp 0x7474
movq 0x9b55(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
callq 0x3150
movl %eax, -0x70(%rbp)
cmpl $0x0, %eax
je 0x7866
movl -0x70(%rbp), %eax
movb %al, -0x6a(%rbp)
cmpl $0x103, -0x70(%rbp)     # imm = 0x103
jne 0x74ad
callq 0x3a90
movq %rax, %rdi
callq 0xa430
jmp 0x7474
cmpl $0x102, -0x70(%rbp)     # imm = 0x102
jne 0x74c5
callq 0x3a90
movq %rax, %rdi
callq 0xa510
jmp 0x7474
cmpl $0x104, -0x70(%rbp)     # imm = 0x104
jne 0x74dd
callq 0x3a90
movq %rax, %rdi
callq 0xa5f0
jmp 0x7474
cmpl $0x105, -0x70(%rbp)     # imm = 0x105
jne 0x74f8
callq 0x3a90
movq %rax, %rdi
callq 0xa6d0
jmp 0x7474
movsbl -0x6a(%rbp), %eax
cmpl $0x71, %eax
je 0x750a
movsbl -0x6a(%rbp), %eax
cmpl $0x51, %eax
jne 0x7516
movq -0x120(%rbp), %rdi
callq 0x7ce0
movsbl -0x6a(%rbp), %eax
cmpl $0x78, %eax
jne 0x7861
movl $0x0, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
callq 0x3a90
movq %rax, %rdi
leaq -0x74(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0xb9d0
movq -0x120(%rbp), %rdi
movq 0x48(%rdi), %rax
movq %rax, -0x148(%rbp)
callq 0x71c0
movq -0x148(%rbp), %rdi
movl %eax, %esi
movl -0x74(%rbp), %edx
subl $0x0, %edx
movl -0x78(%rbp), %ecx
subl $0x3, %ecx
leaq -0x7c(%rbp), %r8
callq 0x5e40
testb $0x1, %al
jne 0x7584
jmp 0x782f
callq 0x3a90
movq -0x120(%rbp), %rdi
movq %rax, -0x150(%rbp)
callq 0x71c0
movq -0x150(%rbp), %rdi
movl %eax, %esi
leaq -0x78(%rbp), %rdx
leaq -0x74(%rbp), %rcx
callq 0xbc20
movq -0x120(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x58d0
movq -0x120(%rbp), %rdi
movl -0x78(%rbp), %esi
movl -0x74(%rbp), %edx
callq 0x7e40
cmpl $0x0, -0x7c(%rbp)
je 0x76e6
movq -0x120(%rbp), %rdi
movl -0x7c(%rbp), %eax
movl %eax, -0x154(%rbp)
callq 0x71c0
movl %eax, %ecx
movl -0x154(%rbp), %eax
cmpl %ecx, %eax
jne 0x76e4
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x35e0
movq -0x160(%rbp), %rdx
leaq 0x4d96(%rip), %rsi      # 0xc3ba
leaq -0xa0(%rbp), %rdi
callq 0x42f0
jmp 0x7632
leaq -0xa1(%rbp), %rdi
callq 0x3400
callq 0x3a90
movq %rax, -0x168(%rbp)
jmp 0x764c
leaq -0xc8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3190
jmp 0x7661
movq -0x168(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xaf80
jmp 0x7676
leaq -0xc8(%rbp), %rdi
callq 0x3200
leaq -0xa0(%rbp), %rdi
callq 0x3200
jmp 0x76e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa1(%rbp), %rdi
callq 0x3400
jmp 0x7873
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x76d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3200
leaq -0xa0(%rbp), %rdi
callq 0x3200
jmp 0x7873
jmp 0x76e6
callq 0x3a90
movq %rax, -0x178(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x35e0
movq -0x170(%rbp), %rdx
leaq 0x4c4d(%rip), %rsi      # 0xc360
leaq -0xe8(%rbp), %rdi
callq 0x42f0
jmp 0x7721
movq -0x178(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x9d00
jmp 0x7736
leaq -0xe8(%rbp), %rdi
callq 0x3200
leaq -0xe9(%rbp), %rdi
callq 0x3400
movq -0x120(%rbp), %rdi
callq 0x7880
callq 0x3a90
movq %rax, -0x188(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x35e0
movq -0x180(%rbp), %rdx
leaq 0x4c06(%rip), %rsi      # 0xc38d
leaq -0x110(%rbp), %rdi
callq 0x42f0
jmp 0x7795
movq -0x188(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x9d00
jmp 0x77aa
leaq -0x110(%rbp), %rdi
callq 0x3200
leaq -0x111(%rbp), %rdi
callq 0x3400
jmp 0x7849
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x77ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x3200
leaq -0xe9(%rbp), %rdi
callq 0x3400
jmp 0x7873
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x7821
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x3200
leaq -0x111(%rbp), %rdi
callq 0x3400
jmp 0x7873
callq 0x3a90
movq %rax, %rdi
callq 0xbe60
callq 0x3a90
movq %rax, %rdi
callq 0xbe60
movsbl -0x6a(%rbp), %eax
cmpl $0x71, %eax
jne 0x785f
callq 0x3a90
movq %rax, %rdi
callq 0xaf60
jmp 0x7861
jmp 0x7474
movb $0x1, %al
andb $0x1, %al
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x35d0
nopl (%rax)