// File: nesro[P]NCursesGomoku/src/game.cpp
// Function: CGame::checkForWin()
void CGame::checkForWin(void) {
	int x;
	int y;
	int direction;
	char message[CBoard::MESSAGE_LENGTH];

	int playerToCheck = (m_PlayerOnTurn + 1) % 2;

	/* sequences of "xxxxx" and "ooooo" */
	char playerWinningSequence[2][6] = { { PLAYER_0_CHAR, PLAYER_0_CHAR,
			PLAYER_0_CHAR, PLAYER_0_CHAR, PLAYER_0_CHAR, '\0' }, {
			PLAYER_1_CHAR, PLAYER_1_CHAR, PLAYER_1_CHAR, PLAYER_1_CHAR,
			PLAYER_1_CHAR, '\0' } };

	if (m_Players[playerToCheck]->m_Surrender) {

		lastMove();

		memset(message, '\0', CBoard::MESSAGE_LENGTH);
		sprintf(message, " (%c) surrender! Press \"q\".",
				m_Players[playerToCheck]->m_Mark);

		m_Board->printMessage(message);
		usleep(1000000);

		playerCleanup();

		waitForChar('q', 'Q');

		m_Status = STATUS_MENU;
		return;
	}

	if (m_Board->m_StonesOnBoard
			>= m_Board->BOARD_HEIGHT * m_Board->BOARD_HEIGHT) {

		lastMove();

		m_Board->printMessage(" Draw! Press \"q\".");

		playerCleanup();

		waitForChar('q', 'Q');

		m_Status = STATUS_MENU;
		return;
	}

	/* find for winning sequence */
	if (m_Board->searchFor(x, y, direction,
			playerWinningSequence[playerToCheck])) {

		lastMove();

		memset(message, '\0', CBoard::MESSAGE_LENGTH);
		sprintf(message, " Player \"%c\" WINS! Press \"q\".",
				m_Players[playerToCheck]->m_Mark);

		m_Board->printMessage(message);

		waitForChar('q', 'Q');

		playerCleanup();

		m_Status = STATUS_MENU;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movl 0x58(%rax), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movq -0x58(%rbp), %rax
movl %edx, -0x44(%rbp)
movq 0x2b44(%rip), %rcx      # 0x8b14
movq %rcx, -0x50(%rbp)
movl 0x2b42(%rip), %ecx      # 0x8b1c
movl %ecx, -0x48(%rbp)
movslq -0x44(%rbp), %rcx
movq 0x40(%rax,%rcx,8), %rax
testb $0x1, 0x8(%rax)
je 0x6072
movq -0x58(%rbp), %rdi
callq 0x6180
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x3180
movq -0x58(%rbp), %rax
leaq -0x40(%rbp), %rdi
movslq -0x44(%rbp), %rcx
movq 0x40(%rax,%rcx,8), %rax
movsbl 0x9(%rax), %edx
leaq 0x2d33(%rip), %rsi      # 0x8d58
movb $0x0, %al
callq 0x3080
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4d00
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x3390
movq -0x58(%rbp), %rdi
callq 0x55a0
movq -0x58(%rbp), %rdi
movl $0x71, %esi
movl $0x51, %edx
callq 0x61c0
movq -0x58(%rbp), %rax
movl $0x1, (%rax)
jmp 0x616c
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0xe1, 0x24(%rax)
jl 0x60cb
movq -0x58(%rbp), %rdi
callq 0x6180
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rdi
leaq 0x2cd9(%rip), %rsi      # 0x8d74
callq 0x4d00
movq -0x58(%rbp), %rdi
callq 0x55a0
movq -0x58(%rbp), %rdi
movl $0x71, %esi
movl $0x51, %edx
callq 0x61c0
movq -0x58(%rbp), %rax
movl $0x1, (%rax)
jmp 0x616c
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rdi
movslq -0x44(%rbp), %rax
leaq -0x50(%rbp), %r8
imulq $0x6, %rax, %rax
addq %rax, %r8
leaq -0xc(%rbp), %rsi
leaq -0x10(%rbp), %rdx
leaq -0x14(%rbp), %rcx
callq 0x4770
testb $0x1, %al
jne 0x60f9
jmp 0x616c
movq -0x58(%rbp), %rdi
callq 0x6180
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x3180
movq -0x58(%rbp), %rax
leaq -0x40(%rbp), %rdi
movslq -0x44(%rbp), %rcx
movq 0x40(%rax,%rcx,8), %rax
movsbl 0x9(%rax), %edx
leaq 0x2c58(%rip), %rsi      # 0x8d86
movb $0x0, %al
callq 0x3080
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4d00
movq -0x58(%rbp), %rdi
movl $0x71, %esi
movl $0x51, %edx
callq 0x61c0
movq -0x58(%rbp), %rdi
callq 0x55a0
movq -0x58(%rbp), %rax
movl $0x1, (%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)