I have made a tic tac toe for two players and written down some functions to do the decision making about who is the winner. I have gone through some cases while testing but need advice to see if I am in the right track and also if all the winning positions are being taken care of.I would like to know even if this can be simplified.Here:$state = [&#10008;,-,-,-,-,&#10008;,-,-,-,-,&#10008;,-,-,-,-,&#10008;]The function is for grids starting from 3X3 to 7X7.PHPfunction whoIsWinning($state){    $n = sqrt(count($state));    $rows = $this->isWin($state, $this->genPaths($n, 0,     1,      $n, $n));    $cols = $this->isWin($state, $this->genPaths($n, 0,     $n,     1,  $n));    $diUp = $this->isWin($state, $this->genPaths(1, $n-1,  $n-1,   0,  $n));    $diDn = $this->isWin($state, $this->genPaths(1,  0,     $n+1,   0,  $n));    if ($rows !== '-') return $rows;    if ($cols !== '-') return $cols;    if ($diUp !== '-') return $diUp;    return $diDn;}/** * Function to generate the paths to win * @param $count * @param $start * @param $incrementA * @param $incrementB * @param $lengthToWin * @return array */function genPaths($count, $start, $incrementA, $incrementB, $lengthToWin){    $paths = [];    if($lengthToWin > 3) {        $lengthToWin = $lengthToWin - 1;    }    for ($i = 0; $i < $count; $i++) {        $path = [];        for($j = 0; $j < $lengthToWin; $j++) {            array_push($path, $start + $i * $incrementB + $j * $incrementA);        }        array_push($paths, $path);    }    return $paths;}/** * @param $state * @param $paths * @return string */function isWin($state, $paths){    for ($i = 0; $i < count($paths); $i++) {        $currentPathResult = $this->isPathWin($state, $paths[$i]);        if ($currentPathResult != '-')            return $currentPathResult;    }    return '-';}/** * @param $state * @param $path * @return string */function isPathWin($state, $path){    $first = $state[$path[0]];    for ($j = 1; $j < count($path); $j++) {        $compareToFirst = $state[$path[$j]];        if ($compareToFirst != $first)            return '-';    }    return $first;}
Noughts and Crosses winner declaration in a game of variable square board size
php;algorithm;tic tac toe