// File: 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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x28(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x5bf7
movl $0x0, -0x1c(%rbp)
movq -0x28(%rbp), %rdx
movl -0x1c(%rbp), %eax
movl 0xc(%rdx), %ecx
movl 0x10(%rdx), %edx
subl $0x1, %edx
subl %edx, %ecx
cmpl %ecx, %eax
jge 0x5be7
jmp 0x5b82
movq -0x28(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rcx
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3bb0
cmpl -0x14(%rbp), %eax
jne 0x5bd5
movq -0x28(%rbp), %rcx
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x5bd3
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5e2c
jmp 0x5b82
movl $0x0, -0x20(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5b6a
jmp 0x5be9
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x5b53
movl $0x0, -0x1c(%rbp)
movq -0x28(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0xc(%rcx), %eax
jge 0x5ca2
movl $0x0, -0x18(%rbp)
movq -0x28(%rbp), %rdx
movl -0x18(%rbp), %eax
movl 0x8(%rdx), %ecx
movl 0x10(%rdx), %edx
subl $0x1, %edx
subl %edx, %ecx
cmpl %ecx, %eax
jge 0x5c92
jmp 0x5c2d
movq -0x28(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rcx
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3bb0
cmpl -0x14(%rbp), %eax
jne 0x5c80
movq -0x28(%rbp), %rcx
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x5c7e
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5e2c
jmp 0x5c2d
movl $0x0, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x5c15
jmp 0x5c94
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5bfe
movl $0x0, -0x1c(%rbp)
movq -0x28(%rbp), %rdx
movl -0x1c(%rbp), %eax
movl 0xc(%rdx), %ecx
movl 0x10(%rdx), %edx
subl $0x1, %edx
subl %edx, %ecx
cmpl %ecx, %eax
jge 0x5d63
movl $0x0, -0x18(%rbp)
movq -0x28(%rbp), %rdx
movl -0x18(%rbp), %eax
movl 0x8(%rdx), %ecx
movl 0x10(%rdx), %edx
subl $0x1, %edx
subl %edx, %ecx
cmpl %ecx, %eax
jge 0x5d53
jmp 0x5ce2
movq -0x28(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rcx
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3bb0
cmpl -0x14(%rbp), %eax
jne 0x5d3e
movq -0x28(%rbp), %rcx
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x5d3c
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5e2c
jmp 0x5ce2
movl $0x0, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x5cca
jmp 0x5d55
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5ca9
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rcx
movl -0x1c(%rbp), %eax
movl 0x10(%rcx), %ecx
subl $0x2, %ecx
addl $0x0, %ecx
cmpl %ecx, %eax
jle 0x5e25
movl $0x0, -0x18(%rbp)
movq -0x28(%rbp), %rdx
movl -0x18(%rbp), %eax
movl 0x8(%rdx), %ecx
movl 0x10(%rdx), %edx
subl $0x1, %edx
subl %edx, %ecx
cmpl %ecx, %eax
jge 0x5e15
jmp 0x5da7
movq -0x28(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rcx
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3bb0
cmpl -0x14(%rbp), %eax
jne 0x5e00
movq -0x28(%rbp), %rcx
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl 0x10(%rcx), %eax
jne 0x5dfe
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5e2c
jmp 0x5da7
movl $0x0, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x5d8f
jmp 0x5e17
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5d70
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)