// File: /workspace/github_cpp_makefile_star2_O2/syky27[P]TicTacToe/src/DNMap.cpp
// Function: DNMap::checkForWinnerWithSymbol(DNCellState)
DNCellState DNMap::checkForWinnerWithSymbol(DNCellState symbol)
{ // check, which checks for backwards diagonal runs below >>>
    int row = 0, col = 0, i = 0;



    for (row = 0; row < this->row; row++) // This first for loop checks every row
    {
        for (col = 0; col < (this->col - (this->goal - 1)); col++) // And all columns until N away from the end
        {
            while (this->my_map[row][col]->getState() == symbol) // For consecutive rows of the current player's mark
            {
                col++;
                i++;
                if (i == this->goal) {
                    return symbol;
                }
            }
            i = 0;
        }
    }

    for (col = 0; col < this->col; col++) // This one checks for columns of consecutive marks
    {
        for (row = 0; row < (this->row - (this->goal - 1)); row++) {
            while (this->my_map[row][col]->getState() == symbol) {
                row++;
                i++;
                if (i == this->goal) {
                    return symbol;
                }
            }
            i = 0;
        }
    }

    for (col = 0; col < (this->col - (this->goal - 1)); col++) // This one checks for "forwards" diagonal runs
    {
        for (row = 0; row < (this->row - (this->goal - 1)); row++) {
            while (this->my_map[row][col]->getState() == symbol) {
                row++;
                col++;
                i++;
                if (i == this->goal) {
                    return symbol;
                }
            }
            i = 0;
        }
    }
    // Finally, the backwards diagonals:
    for (col = this->col - 1; col > 0 + (this->goal - 2); col--) // Start from the last column and go until N columns from the first
    { // The math seems strange here but the numbers work out when you trace them
        for (row = 0; row < (this->row - (this->goal - 1)); row++) // Start from the first row and go until N rows from the last
        {
            while (this->my_map[row][col]->getState() == symbol) // If the current player's character is there
            {
                row++; // Go down a row
                col--; // And back a column
                i++; // The i variable tracks how many consecutive marks have been found
                if (i == this->goal) // Once i == N
                {
                    return symbol; // Return the current player number to the
                } // winnner variable in the playGame function
            } // If it breaks out of the while loop, there weren't N consecutive marks
            i = 0; // So make i = 0 again
        } // And go back into the for loop, incrementing the row to check from
    }

    return EMPTY; // If we got to here, no winner has been detected,
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0x18(%rdi), %r13
xorl %ecx, %ecx
movq %r13, 0x8(%rsp)
movslq 0x8(%r14), %rax
cmpq %rax, %rcx
jge 0x4922
movq %rcx, 0x10(%rsp)
xorl %ebp, %ebp
movl 0xc(%r14), %eax
subl 0x10(%r14), %eax
incl %eax
cmpl %eax, %ebp
jge 0x4911
movslq %ebp, %rax
leaq (,%rax,8), %r12
addq %r13, %r12
xorl %r15d, %r15d
movq (%r12,%r15,8), %rdi
callq 0x3868
cmpl %ebx, %eax
jne 0x490a
incq %r15
cmpl 0x10(%r14), %r15d
jne 0x48ef
jmp 0x4a7d
addl %r15d, %ebp
incl %ebp
jmp 0x48d0
movq 0x10(%rsp), %rcx
incq %rcx
addq $0x320, %r13            # imm = 0x320
jmp 0x48c0
xorl %r15d, %r15d
movslq 0xc(%r14), %r13
cmpq %r13, %r15
jge 0x4987
xorl %r13d, %r13d
movl %eax, %ecx
subl 0x10(%r14), %ecx
incl %ecx
cmpl %ecx, %r13d
jge 0x497c
movslq %r13d, %rax
imulq $0x320, %rax, %r12      # imm = 0x320
addq 0x8(%rsp), %r12
xorl %ebp, %ebp
movq (%r12), %rdi
callq 0x3868
cmpl %ebx, %eax
jne 0x4970
incl %ebp
addq $0x320, %r12            # imm = 0x320
cmpl 0x10(%r14), %ebp
jne 0x494f
jmp 0x4a7d
addl %ebp, %r13d
incl %r13d
movl 0x8(%r14), %eax
jmp 0x4931
incq %r15
addq $0x8, 0x8(%rsp)
jmp 0x4925
movl 0x10(%r14), %ecx
leaq 0x18(%r14), %rdx
movq %rdx, 0x10(%rsp)
xorl %esi, %esi
movl %r13d, %edx
subl %ecx, %edx
incl %edx
cmpl %edx, %esi
jge 0x4a12
xorl %r15d, %r15d
movl %eax, %edx
subl %ecx, %edx
incl %edx
cmpl %edx, %r15d
jge 0x4a0a
movslq %r15d, %rax
movl %esi, 0x8(%rsp)
movslq %esi, %rcx
imulq $0x320, %rax, %rax      # imm = 0x320
leaq (%rax,%rcx,8), %r13
addq 0x10(%rsp), %r13
xorl %ebp, %ebp
xorl %r12d, %r12d
movq (%r13), %rdi
callq 0x3868
cmpl %ebx, %eax
jne 0x49f3
decl %r12d
addq $0x328, %r13            # imm = 0x328
incq %rbp
cmpl 0x10(%r14), %ebp
jne 0x49ce
jmp 0x4a7d
movl 0x8(%rsp), %esi
subl %r12d, %esi
subl %r12d, %r15d
incl %r15d
movl 0x8(%r14), %eax
movl 0x10(%r14), %ecx
jmp 0x49a4
incl %esi
movl 0xc(%r14), %r13d
jmp 0x4996
xorl %r15d, %r15d
cmpl %ecx, %r13d
jl 0x4a80
decl %r13d
xorl %esi, %esi
movl %eax, %edx
subl %ecx, %edx
incl %edx
cmpl %edx, %esi
jge 0x4a15
movq %rsi, 0x8(%rsp)
movslq %esi, %rax
movslq %r13d, %rcx
imulq $0x320, %rax, %rax      # imm = 0x320
leaq (%rax,%rcx,8), %rbp
addq 0x10(%rsp), %rbp
xorl %r12d, %r12d
movq (%rbp), %rdi
callq 0x3868
cmpl %ebx, %eax
jne 0x4a66
incq %r12
addq $0x318, %rbp            # imm = 0x318
cmpl 0x10(%r14), %r12d
jne 0x4a47
jmp 0x4a7d
subl %r12d, %r13d
movq 0x8(%rsp), %rsi
addl %r12d, %esi
incl %esi
movl 0x8(%r14), %eax
movl 0x10(%r14), %ecx
jmp 0x4a1f
movl %ebx, %r15d
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq