// File: /workspace/github_cpp_makefile_star2_O3/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 0x2a8f
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 0x31f6
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 0x2a30
callq 0x2090
movl $0x2a, %ecx
subl %r14d, %ecx
cltd
idivl %ecx
testl %edx, %edx
je 0x29c0
movq 0x20(%rbx), %rax
cmpl $0x0, (%rax,%r14,4)
movl 0x4(%rsp), %edx
movl 0x8(%rsp), %ecx
jle 0x29aa
movslq 0xc(%rsp), %rdi
leaq 0x2a77(%rip), %r8       # 0x5400
movl (%r8,%rdi,8), %esi
movl 0x4(%r8,%rdi,8), %edi
xorl %r8d, %r8d
addl %edi, %ecx
addl %esi, %edx
movl %edx, 0x4(%rsp)
movl %ecx, 0x8(%rsp)
incl %r8d
cmpl (%rax,%r14,4), %r8d
jl 0x2995
movq 0x10(%rbx), %rdi
movsbl 0x9(%rbx), %esi
callq 0x2e6c
testb %al, %al
je 0x2a30
jmp 0x2a81
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movsbl 0x9(%rbx), %edx
movq %rbp, %rdi
leaq 0x29ab(%rip), %rsi      # 0x5386
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
callq 0x31f6
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 0x2984(%rip), %rsi      # 0x5397
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
callq 0x31f6
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 0x295d(%rip), %rsi      # 0x53b6
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x31f6
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x22c0
movq %rbx, %rdi
callq 0x43b6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq