// File: /workspace/github_cpp_makefile_star2_O1/nesro[P]NCursesGomoku/src/ai.cpp
// Function: CAI::nextMove()
void CAI::nextMove(void) {

	/* nothing to do here */
	if (m_IsWinner == true) {
		return;
	}

	int x = 0;
	int y = 0;
	int direction = 0;

	char message[CBoard::MESSAGE_LENGTH];

	for (int i = 0; i < STRATEGIES; i++) {

		memset(message, 0, CBoard::MESSAGE_LENGTH);
		sprintf(message, " AI (%c) think about: %s", m_Mark, m_Patterns[i]);
		m_Board->printMessage(message);

		usleep(100000);

		if (m_Board->searchFor(x, y, direction, m_Patterns[i])) {

			/* AI can make mistake*/
			if ((rand() % (42 - i)) == 0) {
				memset(message, 0, CBoard::MESSAGE_LENGTH);
				sprintf(message, " AI (%c): Oh no!", m_Mark);
				m_Board->printMessage(message);
				usleep(1500000);

				memset(message, 0, CBoard::MESSAGE_LENGTH);
				sprintf(message, " AI (%c): I made a mistake! :(", m_Mark);
				m_Board->printMessage(message);
				usleep(1500000);

				continue;
			}

			for (int j = 0; j < m_Moves[i]; j++) {
				x += CBoard::DIRECTIONS[direction][0];
				y += CBoard::DIRECTIONS[direction][1];

			}

			if (m_Board->addStone(m_Mark, x, y)) {
				return;
			}
		}
	}

	memset(message, 0, CBoard::MESSAGE_LENGTH);
	sprintf(message, " AI (%c): I go random.", m_Mark);
	m_Board->printMessage(message);
	usleep(1000000);

	goRandom();
}

// Assembly:
cmpb $0x0, 0xa(%rdi)
jne 0x2a87
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
xorl %eax, %eax
leaq 0x4(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x8(%rsp), %r15
movl %eax, (%r15)
leaq 0xc(%rsp), %r12
movl %eax, (%r12)
leaq 0x2a7f(%rip), %r13      # 0x536d
leaq 0x10(%rsp), %rbp
xorl %r14d, %r14d
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movsbl 0x9(%rbx), %edx
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rcx
movq %rbp, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
callq 0x33fa
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x22c0
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %r8
leaq 0x4(%rsp), %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x2f52
testb %al, %al
je 0x2a28
callq 0x2090
movl $0x2a, %ecx
subl %r14d, %ecx
cltd
idivl %ecx
testl %edx, %edx
je 0x29b8
movq 0x20(%rbx), %rax
cmpl $0x0, (%rax,%r14,4)
jle 0x299a
movslq 0xc(%rsp), %rdx
leaq 0x2a6f(%rip), %rsi      # 0x53f0
movl (%rsi,%rdx,8), %ecx
movl 0x4(%rsi,%rdx,8), %edx
xorl %esi, %esi
addl %ecx, 0x4(%rsp)
addl %edx, 0x8(%rsp)
incl %esi
cmpl (%rax,%r14,4), %esi
jl 0x298a
movq 0x10(%rbx), %rdi
movsbl 0x9(%rbx), %esi
movl 0x4(%rsp), %edx
movl 0x8(%rsp), %ecx
callq 0x2e6c
testb %al, %al
je 0x2a28
jmp 0x2a79
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movsbl 0x9(%rbx), %edx
movq %rbp, %rdi
leaq 0x29b3(%rip), %rsi      # 0x5386
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
callq 0x33fa
movl $0x16e360, %edi         # imm = 0x16E360
callq 0x22c0
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movsbl 0x9(%rbx), %edx
movq %rbp, %rdi
leaq 0x298c(%rip), %rsi      # 0x5397
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
callq 0x33fa
movl $0x16e360, %edi         # imm = 0x16E360
callq 0x22c0
incq %r14
cmpq $0x15, %r14
jne 0x28f6
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movsbl 0x9(%rbx), %edx
leaq 0x2965(%rip), %rsi      # 0x53b6
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x33fa
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x22c0
movq %rbx, %rdi
callq 0x45b6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq