// File: syky27[P]TicTacToe/src/DNSmarterBotPlayer.cpp
// Function: DNSmarterBotPlayer::triggerTurn(int, int)
bool DNSmarterBotPlayer::triggerTurn(int y, int x)
{

    for (size_t i = 1; i < game_map->getMapSize() - 1; i++) {
        for (size_t j = 1; j < game_map->getMapSize() - 1; j++) {
            if (game_map->my_map[i][j]->getState() != EMPTY) {
                if (game_map->my_map[i + 1][j]->getState() == EMPTY) {
                    availableMoves.insert(make_pair(i + 1, j));
                }
                if (game_map->my_map[i][j + 1]->getState() == EMPTY) {
                    availableMoves.insert(make_pair(i, j + 1));
                }
                //                if (game_map->my_map[i+1][j+1]->getState() == EMPTY) {
                //                    availableMoves.insert(make_pair(i+1,j+1));
                //                }
                if (game_map->my_map[i - 1][j]->getState() == EMPTY) {
                    availableMoves.insert(make_pair(i - 1, j));
                }
                if (game_map->my_map[i][j - 1]->getState() == EMPTY) {
                    availableMoves.insert(make_pair(i, j - 1));
                }
                //                if (game_map->my_map[i-1][j-1]->getState() == EMPTY) {
                //                    availableMoves.insert(make_pair(i-1,j-1));
                //                }
                //                if (game_map->my_map[i+1][j-1]->getState() == EMPTY) {
                //                    availableMoves.insert(make_pair(i+1,j-1));
                //                }
                //                if (game_map->my_map[i-1][j+1]->getState() == EMPTY) {
                //                    availableMoves.insert(make_pair(i-1,j+1));
                //                }


            }
        }
    }


    int x_p;
    int y_p;
   // int y_plus;
    int x_plus;

    if (availableMoves.size() > 0) {
        srand(time(0));
        size_t ran = rand() % availableMoves.size();
        set <pair<int, int> >::iterator it = availableMoves.begin();
        for (; ran != 0; ran--) *it++;

        x_p = it->first;
        y_p = it->second;
     //   y_plus = y_p + 3;
        x_plus = x_p + 3;

        it = availableMoves.begin();
        for (; it != availableMoves.end(); it++) {
            DNLogService::sharedObject() << it->first << "-" << it->second << "\n";
        }
    }
    else {
        srand(time(0));
        x_p = (rand() % 10) + 1;
        y_p = (rand() % 10) + 1;
     //   y_plus = y_p + 3;
        x_plus = x_p + 3;
    }

    DNCellState state;
    if (this->game_map->recordMove(this->getSymbol(), y_p, x_p, state)) {
        usleep(100000);
        DNWindow::getInstance().drawSymbolBetter(this->getSymbol(), y_p, x_plus);
        this->game_map->debugToFile();
        if (state != EMPTY) {
            if (state == this->getSymbol()) {
                string win = " is Winner!!!";
                win = this->getNick() + win;
                sleep(3);
                DNWindow::getInstance().terminateWithErrorMessage(win);
            }

        }
        else {
            availableMoves.clear();
            return true;
        }
    }


    availableMoves.clear();

    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq $0x1, -0x20(%rbp)
movq -0x1d0(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, -0x1d8(%rbp)
movq 0x48(%rax), %rdi
callq 0x58b0
movq %rax, %rcx
movq -0x1d8(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x8534
movq $0x1, -0x28(%rbp)
movq -0x1d0(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, -0x1e0(%rbp)
movq 0x48(%rax), %rdi
callq 0x58b0
movq %rax, %rcx
movq -0x1e0(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x8521
movq -0x1d0(%rbp), %rax
movq 0x48(%rax), %rax
addq $0x18, %rax
imulq $0x320, -0x20(%rbp), %rcx # imm = 0x320
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3bb0
cmpl $0x0, %eax
je 0x850e
movq -0x1d0(%rbp), %rax
movq 0x48(%rax), %rax
addq $0x18, %rax
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3bb0
cmpl $0x0, %eax
jne 0x833e
movq -0x1d0(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x1e8(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8a70
movq %rax, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x8aa0
movq -0x1e8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x8a20
movq %rax, -0x58(%rbp)
movb %dl, -0x50(%rbp)
movq -0x1d0(%rbp), %rax
movq 0x48(%rax), %rax
addq $0x18, %rax
imulq $0x320, -0x20(%rbp), %rcx # imm = 0x320
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x3bb0
cmpl $0x0, %eax
jne 0x83c5
movq -0x1d0(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x1f0(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x8ad0
movq %rax, -0x70(%rbp)
movq %rdx, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x8aa0
movq -0x1f0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x8a20
movq %rax, -0x88(%rbp)
movb %dl, -0x80(%rbp)
movq -0x1d0(%rbp), %rax
movq 0x48(%rax), %rax
addq $0x18, %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3bb0
cmpl $0x0, %eax
jne 0x846a
movq -0x1d0(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x1f8(%rbp)
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8a70
movq %rax, -0xa0(%rbp)
movq %rdx, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x8aa0
movq -0x1f8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x8a20
movq %rax, -0xb8(%rbp)
movb %dl, -0xb0(%rbp)
movq -0x1d0(%rbp), %rax
movq 0x48(%rax), %rax
addq $0x18, %rax
imulq $0x320, -0x20(%rbp), %rcx # imm = 0x320
addq %rcx, %rax
movq -0x28(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3bb0
cmpl $0x0, %eax
jne 0x850c
movq -0x1d0(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x200(%rbp)
movq -0x28(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xd8(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x8ad0
movq %rax, -0xd0(%rbp)
movq %rdx, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x8aa0
movq -0x200(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x8a20
movq %rax, -0xe8(%rbp)
movb %dl, -0xe0(%rbp)
jmp 0x850e
jmp 0x8510
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x8252
jmp 0x8523
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x8218
movq -0x1d0(%rbp), %rdi
addq $0x50, %rdi
callq 0x8b00
cmpq $0x0, %rax
jbe 0x86fa
xorl %eax, %eax
movl %eax, %edi
callq 0x3320
movl %eax, %edi
callq 0x3340
callq 0x30d0
movq -0x1d0(%rbp), %rdi
cltq
movq %rax, -0x208(%rbp)
addq $0x50, %rdi
callq 0x8b00
movq -0x1d0(%rbp), %rdi
movq %rax, %rcx
movq -0x208(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, -0x100(%rbp)
addq $0x50, %rdi
callq 0x8b20
movq %rax, -0x108(%rbp)
cmpq $0x0, -0x100(%rbp)
je 0x85e8
leaq -0x108(%rbp), %rdi
xorl %esi, %esi
callq 0x8b50
movq %rax, -0x110(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x8b90
movq -0x100(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x100(%rbp)
jmp 0x85a9
leaq -0x108(%rbp), %rdi
callq 0x8bb0
movl (%rax), %eax
movl %eax, -0xec(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x8bb0
movq -0x1d0(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0xf0(%rbp)
movl -0xec(%rbp), %eax
addl $0x3, %eax
movl %eax, -0xf4(%rbp)
addq $0x50, %rdi
callq 0x8b20
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x1d0(%rbp), %rdi
addq $0x50, %rdi
callq 0x8c00
movq %rax, -0x120(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x8bd0
testb $0x1, %al
jne 0x8678
jmp 0x86f8
callq 0x43c0
movq %rax, -0x218(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x8bb0
movq -0x218(%rbp), %rdi
movl (%rax), %esi
callq 0x55d0
movq %rax, %rdi
leaq 0x3dc3(%rip), %rsi      # 0xc46b
callq 0x5520
movq %rax, -0x210(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x8bb0
movq -0x210(%rbp), %rdi
movl 0x4(%rax), %esi
callq 0x55d0
movq %rax, %rdi
leaq 0x3e81(%rip), %rsi      # 0xc55a
callq 0x5520
leaq -0x108(%rbp), %rdi
xorl %esi, %esi
callq 0x8b50
movq %rax, -0x128(%rbp)
jmp 0x8645
jmp 0x8745
xorl %eax, %eax
movl %eax, %edi
callq 0x3320
movl %eax, %edi
callq 0x3340
callq 0x30d0
movl $0xa, %ecx
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, -0xec(%rbp)
callq 0x30d0
movl $0xa, %ecx
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, -0xf0(%rbp)
movl -0xec(%rbp), %eax
addl $0x3, %eax
movl %eax, -0xf4(%rbp)
movq -0x1d0(%rbp), %rdi
movq 0x48(%rdi), %rax
movq %rax, -0x220(%rbp)
callq 0x71c0
movq -0x220(%rbp), %rdi
movl %eax, %esi
movl -0xf0(%rbp), %edx
movl -0xec(%rbp), %ecx
leaq -0x12c(%rbp), %r8
callq 0x5e40
testb $0x1, %al
jne 0x8786
jmp 0x89a5
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x3500
callq 0x3a90
movq -0x1d0(%rbp), %rdi
movq %rax, -0x228(%rbp)
callq 0x71c0
movq -0x228(%rbp), %rdi
movl %eax, %esi
leaq -0xf0(%rbp), %rdx
leaq -0xf4(%rbp), %rcx
callq 0xbab0
movq -0x1d0(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x58d0
cmpl $0x0, -0x12c(%rbp)
je 0x898d
movq -0x1d0(%rbp), %rdi
movl -0x12c(%rbp), %eax
movl %eax, -0x22c(%rbp)
callq 0x71c0
movl %eax, %ecx
movl -0x22c(%rbp), %eax
cmpl %ecx, %eax
jne 0x898b
leaq -0x151(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x35e0
movq -0x238(%rbp), %rdx
leaq 0x3c43(%rip), %rsi      # 0xc46d
leaq -0x150(%rbp), %rdi
callq 0x42f0
jmp 0x8838
leaq -0x151(%rbp), %rdi
callq 0x3400
movq -0x1d0(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x71e0
jmp 0x8859
leaq -0x188(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x5390
jmp 0x8875
leaq -0x150(%rbp), %rdi
leaq -0x188(%rbp), %rsi
movq %rsi, -0x240(%rbp)
callq 0x34a0
movq -0x240(%rbp), %rdi
callq 0x3200
leaq -0x1a8(%rbp), %rdi
callq 0x3200
movl $0x3, %edi
callq 0x32a0
jmp 0x88b3
callq 0x3a90
movq %rax, -0x248(%rbp)
jmp 0x88c1
leaq -0x1c8(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x3190
jmp 0x88d6
movq -0x248(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0xaf80
jmp 0x88eb
leaq -0x1c8(%rbp), %rdi
callq 0x3200
leaq -0x150(%rbp), %rdi
callq 0x3200
jmp 0x898b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x151(%rbp), %rdi
callq 0x3400
jmp 0x89c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0x897d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3200
jmp 0x897d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x3200
leaq -0x150(%rbp), %rdi
callq 0x3200
jmp 0x89c7
jmp 0x89a3
movq -0x1d0(%rbp), %rdi
addq $0x50, %rdi
callq 0x8c30
movb $0x1, -0x1(%rbp)
jmp 0x89b9
jmp 0x89a5
movq -0x1d0(%rbp), %rdi
addq $0x50, %rdi
callq 0x8c30
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
movq -0x160(%rbp), %rdi
callq 0x35d0
nopw %cs:(%rax,%rax)
nopl (%rax)