// File: /workspace/github_cpp_makefile_star2_O1/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
cmpl $0x0, 0x8(%rdi)
jle 0x51fa
leaq 0x18(%r14), %r15
xorl %ecx, %ecx
movq %rcx, 0x8(%rsp)
movl 0xc(%r14), %eax
subl 0x10(%r14), %eax
incl %eax
testl %eax, %eax
jle 0x51e2
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 0x51cd
incq %rbp
cmpl 0x10(%r14), %ebp
jne 0x51b2
jmp 0x53b5
addl %ebp, %r13d
incl %r13d
movl 0xc(%r14), %eax
subl 0x10(%r14), %eax
incl %eax
cmpl %eax, %r13d
jl 0x51a9
movq 0x8(%rsp), %rcx
incq %rcx
movslq 0x8(%r14), %rax
addq $0x320, %r15            # imm = 0x320
cmpq %rax, %rcx
jl 0x5193
cmpl $0x0, 0xc(%r14)
jle 0x5279
leaq 0x18(%r14), %r15
xorl %ecx, %ecx
movq %rcx, 0x8(%rsp)
movl 0x8(%r14), %eax
subl 0x10(%r14), %eax
incl %eax
testl %eax, %eax
jle 0x5264
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 0x524f
incl %r12d
addq $0x320, %rbp            # imm = 0x320
cmpl 0x10(%r14), %r12d
jne 0x522d
jmp 0x53b5
addl %r12d, %r13d
incl %r13d
movl 0x8(%r14), %eax
subl 0x10(%r14), %eax
incl %eax
cmpl %eax, %r13d
jl 0x521d
movq 0x8(%rsp), %rcx
incq %rcx
movslq 0xc(%r14), %rax
addq $0x8, %r15
cmpq %rax, %rcx
jl 0x5207
movl 0xc(%r14), %ecx
movl 0x10(%r14), %eax
negl %eax
addl %ecx, %eax
incl %eax
testl %eax, %eax
jle 0x532b
leaq 0x18(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movl 0x8(%r14), %ecx
subl 0x10(%r14), %ecx
incl %ecx
testl %ecx, %ecx
jle 0x5313
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 0x52f0
decl %r13d
addq $0x328, %r15            # imm = 0x328
incq %rbp
cmpl 0x10(%r14), %ebp
jne 0x52cc
jmp 0x53b5
movl 0x8(%rsp), %edx
movl %edx, %eax
subl %r13d, %eax
subl %r13d, %r12d
incl %r12d
movl 0x8(%r14), %ecx
subl 0x10(%r14), %ecx
incl %ecx
cmpl %ecx, %r12d
jl 0x52ab
subl %r13d, %edx
movl %edx, %eax
incl %eax
movl 0xc(%r14), %ecx
movl 0x10(%r14), %edx
negl %edx
addl %ecx, %edx
incl %edx
cmpl %edx, %eax
jl 0x529a
xorl %eax, %eax
cmpl 0x10(%r14), %ecx
jl 0x53b7
leaq 0x18(%r14), %rax
movq %rax, 0x8(%rsp)
decl %ecx
movl 0x8(%r14), %eax
subl 0x10(%r14), %eax
incl %eax
testl %eax, %eax
jle 0x53ab
xorl %r12d, %r12d
movl %ecx, %ebp
movslq %r12d, %rax
movslq %ecx, %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 0x538c
incq %r13
addq $0x318, %r15            # imm = 0x318
cmpl 0x10(%r14), %r13d
jne 0x536e
jmp 0x53b5
movl %ebp, %ecx
subl %r13d, %ecx
addl %r13d, %r12d
incl %r12d
movl 0x8(%r14), %eax
subl 0x10(%r14), %eax
incl %eax
cmpl %eax, %r12d
jl 0x5353
subl %r13d, %ebp
movl %ebp, %ecx
xorl %eax, %eax
cmpl 0x10(%r14), %ecx
jge 0x5340
jmp 0x53b7
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq