// File: syky27[P]TicTacToe/src/DNHumanPlayer.cpp
// Function: DNHumanPlayer::triggerTurn(int, int)
bool DNHumanPlayer::triggerTurn(int y, int x)
{
    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 == '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();

                    if (state != EMPTY) {
                        if (state == this->getSymbol()) {
                            string win(" is Winner !!!");
                            win = this->getNick() + win;
                            DNWindow::getInstance().terminateWithErrorMessage(win);
                        }
                    }else{
                        return true;
                    }
                }
        }
        
        if (ch == 'q') {
                DNWindow::getInstance().terminate();
            }
    }
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq 0xbf29(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
callq 0x3150
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
je 0x5366
movl -0x20(%rbp), %eax
movb %al, -0x19(%rbp)
cmpl $0x103, -0x20(%rbp)     # imm = 0x103
jne 0x50d9
callq 0x3a90
movq %rax, %rdi
callq 0xa430
jmp 0x50a0
cmpl $0x102, -0x20(%rbp)     # imm = 0x102
jne 0x50f1
callq 0x3a90
movq %rax, %rdi
callq 0xa510
jmp 0x50a0
cmpl $0x104, -0x20(%rbp)     # imm = 0x104
jne 0x5109
callq 0x3a90
movq %rax, %rdi
callq 0xa5f0
jmp 0x50a0
cmpl $0x105, -0x20(%rbp)     # imm = 0x105
jne 0x5124
callq 0x3a90
movq %rax, %rdi
callq 0xa6d0
jmp 0x50a0
movsbl -0x19(%rbp), %eax
cmpl $0x78, %eax
jne 0x534b
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
callq 0x3a90
movq %rax, %rdi
leaq -0x24(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0xb9d0
movq -0xd0(%rbp), %rdi
movq 0x48(%rdi), %rax
movq %rax, -0xd8(%rbp)
callq 0x71c0
movq -0xd8(%rbp), %rdi
movl %eax, %esi
movl -0x24(%rbp), %edx
subl $0x0, %edx
movl -0x28(%rbp), %ecx
subl $0x3, %ecx
leaq -0x2c(%rbp), %r8
callq 0x5e40
testb $0x1, %al
jne 0x5192
jmp 0x5349
callq 0x3a90
movq -0xd0(%rbp), %rdi
movq %rax, -0xe0(%rbp)
callq 0x71c0
movq -0xe0(%rbp), %rdi
movl %eax, %esi
leaq -0x28(%rbp), %rdx
leaq -0x24(%rbp), %rcx
callq 0xbc20
movq -0xd0(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x58d0
cmpl $0x0, -0x2c(%rbp)
je 0x5341
movq -0xd0(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl %eax, -0xe4(%rbp)
callq 0x71c0
movl %eax, %ecx
movl -0xe4(%rbp), %eax
cmpl %ecx, %eax
jne 0x533f
leaq -0x51(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x35e0
movq -0xf0(%rbp), %rdx
leaq 0x6ec3(%rip), %rsi      # 0xc0e0
leaq -0x50(%rbp), %rdi
callq 0x42f0
jmp 0x5228
leaq -0x51(%rbp), %rdi
callq 0x3400
movq -0xd0(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x71e0
jmp 0x5246
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x5390
jmp 0x525f
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movq %rsi, -0x100(%rbp)
callq 0x34a0
movq -0x100(%rbp), %rdi
callq 0x3200
leaq -0xa8(%rbp), %rdi
callq 0x3200
callq 0x3a90
movq %rax, -0xf8(%rbp)
jmp 0x529c
leaq -0xc8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3190
jmp 0x52ae
movq -0xf8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xaf80
jmp 0x52c3
leaq -0xc8(%rbp), %rdi
callq 0x3200
leaq -0x50(%rbp), %rdi
callq 0x3200
jmp 0x533f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x3400
jmp 0x5378
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x5334
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3200
jmp 0x5334
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3200
leaq -0x50(%rbp), %rdi
callq 0x3200
jmp 0x5378
jmp 0x5347
movb $0x1, -0x1(%rbp)
jmp 0x536a
jmp 0x5349
jmp 0x534b
movsbl -0x19(%rbp), %eax
cmpl $0x71, %eax
jne 0x5361
callq 0x3a90
movq %rax, %rdi
callq 0xaf60
jmp 0x50a0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x35d0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)