| Total Complexity | 21 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class FindWinnerOnATicTacToeGame |
||
| 8 | { |
||
| 9 | public static function tictactoe(array $moves): string |
||
| 10 | { |
||
| 11 | if (empty($moves)) { |
||
| 12 | return ''; |
||
| 13 | } |
||
| 14 | $row = $col = array_fill(0, 2, array_fill(0, 3, 0)); |
||
| 15 | $d1 = $d2 = array_fill(0, 2, 0); |
||
| 16 | foreach ($moves as $k => $v) { |
||
| 17 | [$r, $c, $i] = [$v[0], $v[1], $k % 2]; |
||
| 18 | if (++$row[$i][$r] === 3 || |
||
| 19 | ++$col[$i][$c] === 3 || |
||
| 20 | ($r === $c && ++$d1[$i] === 3) || |
||
| 21 | ($r + $c === 2 && ++$d2[$i] === 3)) { |
||
| 22 | return $i === 0 ? 'A' : 'B'; |
||
| 23 | } |
||
| 24 | } |
||
| 25 | |||
| 26 | return count($moves) === 9 ? 'Draw' : 'Pending'; |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function tictactoe2(array $moves): string |
||
| 62 | } |
||
| 63 | } |
||
| 64 |