// File: /workspace/github_cpp_makefile_star2_O3/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
movl 0x8(%rdi), %ecx
testl %ecx, %ecx
jle 0x5204
leaq 0x18(%r14), %r15
movl 0xc(%r14), %edx
movl 0x10(%r14), %eax
xorl %edi, %edi
movl %edx, %esi
subl %eax, %esi
incl %esi
testl %esi, %esi
jle 0x51f0
movq %rdi, 0x8(%rsp)
xorl %r13d, %r13d
movslq %r13d, %rax
leaq (%r15,%rax,8), %r12
xorl %ebp, %ebp
movq (%r12,%rbp,8), %rdi
callq 0x3a24
cmpl %ebx, %eax
jne 0x51ce
incq %rbp
cmpl 0x10(%r14), %ebp
jne 0x51b3
jmp 0x53bd
addl %ebp, %r13d
incl %r13d
movl 0xc(%r14), %edx
movl 0x10(%r14), %eax
movl %edx, %ecx
subl %eax, %ecx
incl %ecx
cmpl %ecx, %r13d
jl 0x51aa
movl 0x8(%r14), %ecx
movq 0x8(%rsp), %rdi
incq %rdi
movslq %ecx, %rsi
addq $0x320, %r15            # imm = 0x320
cmpq %rsi, %rdi
jl 0x5198
jmp 0x5208
movl 0xc(%r14), %edx
testl %edx, %edx
jle 0x5291
leaq 0x18(%r14), %r15
movl 0x10(%r14), %esi
xorl %edi, %edi
movl %ecx, %eax
subl %esi, %eax
incl %eax
testl %eax, %eax
jle 0x5280
movq %rdi, 0x8(%rsp)
xorl %r13d, %r13d
movslq %r13d, %rax
imulq $0x320, %rax, %rbp      # imm = 0x320
addq %r15, %rbp
xorl %r12d, %r12d
movq (%rbp), %rdi
callq 0x3a24
cmpl %ebx, %eax
jne 0x525e
incl %r12d
addq $0x320, %rbp            # imm = 0x320
cmpl 0x10(%r14), %r12d
jne 0x523c
jmp 0x53bd
addl %r12d, %r13d
incl %r13d
movl 0x8(%r14), %ecx
movl 0x10(%r14), %esi
movl %ecx, %eax
subl %esi, %eax
incl %eax
cmpl %eax, %r13d
jl 0x522c
movl 0xc(%r14), %edx
movq 0x8(%rsp), %rdi
incq %rdi
movslq %edx, %rax
addq $0x8, %r15
cmpq %rax, %rdi
jl 0x521a
jmp 0x5295
movl 0x10(%r14), %esi
movl %edx, %eax
subl %esi, %eax
incl %eax
testl %eax, %eax
jle 0x533b
leaq 0x18(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movl %ecx, %edi
subl %esi, %edi
incl %edi
testl %edi, %edi
jle 0x532b
xorl %r12d, %r12d
movl %eax, %ecx
movslq %r12d, %rax
movl %ecx, 0x8(%rsp)
movslq %ecx, %rcx
imulq $0x320, %rax, %rax      # imm = 0x320
leaq (%rax,%rcx,8), %r15
addq 0x10(%rsp), %r15
xorl %ebp, %ebp
xorl %r13d, %r13d
movq (%r15), %rdi
callq 0x3a24
cmpl %ebx, %eax
jne 0x5300
decl %r13d
addq $0x328, %r15            # imm = 0x328
incq %rbp
cmpl 0x10(%r14), %ebp
jne 0x52dc
jmp 0x53bd
movl 0x8(%rsp), %edi
movl %edi, %eax
subl %r13d, %eax
subl %r13d, %r12d
incl %r12d
movl 0x8(%r14), %ecx
movl 0x10(%r14), %esi
movl %ecx, %edx
subl %esi, %edx
incl %edx
cmpl %edx, %r12d
jl 0x52bb
movl 0xc(%r14), %edx
subl %r13d, %edi
movl %edi, %eax
incl %eax
movl %edx, %edi
subl %esi, %edi
incl %edi
cmpl %edi, %eax
jl 0x52ae
xorl %eax, %eax
cmpl %esi, %edx
jl 0x53bf
leaq 0x18(%r14), %rax
movq %rax, 0x8(%rsp)
decl %edx
movl %ecx, %eax
subl %esi, %eax
incl %eax
testl %eax, %eax
jle 0x53b5
xorl %r12d, %r12d
movl %edx, %ebp
movslq %r12d, %rax
movslq %edx, %rcx
imulq $0x320, %rax, %rax      # imm = 0x320
leaq (%rax,%rcx,8), %r15
addq 0x8(%rsp), %r15
xorl %r13d, %r13d
movq (%r15), %rdi
callq 0x3a24
cmpl %ebx, %eax
jne 0x5392
incq %r13
addq $0x318, %r15            # imm = 0x318
cmpl 0x10(%r14), %r13d
jne 0x5374
jmp 0x53bd
movl %ebp, %edx
subl %r13d, %edx
addl %r13d, %r12d
incl %r12d
movl 0x8(%r14), %ecx
movl 0x10(%r14), %esi
movl %ecx, %eax
subl %esi, %eax
incl %eax
cmpl %eax, %r12d
jl 0x5359
subl %r13d, %ebp
movl %ebp, %edx
xorl %eax, %eax
cmpl %esi, %edx
jge 0x534a
jmp 0x53bf
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq