Even simpler bounds check.

This commit is contained in:
2017-12-19 10:19:37 +01:00
parent bbf8ad85e4
commit 9b0f2cfdb5

View File

@@ -11,16 +11,16 @@ $dir = [0, 1];
$path = ''; $path = '';
$steps = 0; $steps = 0;
while ($maze[$y][$x] != ' ') { while (($maze[$y][$x] ?? ' ') != ' ') {
if (ctype_alpha($maze[$y][$x])) { if (ctype_alpha($maze[$y][$x])) {
$path .= $maze[$y][$x]; $path .= $maze[$y][$x];
} elseif ($maze[$y][$x] == '+') { } elseif ($maze[$y][$x] == '+') {
if ($dir[0] == 0) { if ($dir[0] == 0) {
$dir[0] = ($x == 0 || $maze[$y][$x - 1] == ' ') ? 1 : -1; $dir[0] = ($maze[$y][$x + 1] ?? ' ') == ' ' ? -1 : 1;
$dir[1] = 0; $dir[1] = 0;
} else { } else {
$dir[0] = 0; $dir[0] = 0;
$dir[1] = ($y == 0 || $maze[$y - 1][$x] == ' ') ? 1 : -1; $dir[1] = ($maze[$y + 1][$x] ?? ' ') == ' ' ? -1 : 1;
} }
} }