i have problem about create maze-generator
i have variable $num = 5, and i want output like this :
@ @@@
@ @
@@@ @
@ @
@ @@@
i already trying to solve my problem and the output like this :
@ @@@
@ @
@@@ @
@ @
@@@ @
how to make output correct like i want first? I already write scipt on php like this :
<?php
$num = 5;
$space = $num - 2;
$end = $num - 1;
$left = true;
$mid = false;
$right = false;
$leftCount = 1;
$rightCount = 0;
for ($i = 0; $i < $num; $i++)
{
for ($j = 0; $j < $num; $j++)
{
if ($left) {
$line = ($i % 2 == 0 && $j == 1) ? " ":" 1 ";
($j == $end) ? $left = false:$mid = true;
$leftCount = 0;
$rightCount = 1;
echo $line;
}
else if ($mid)
{
$line = (($i % 2 == 1 && $j == 0) || ($i % 2 == 1 && $j == $end)) ? " 2 ":" ";
($j == $end) ? $mid = false:"";
($rightCount > $leftCount) ? $right = true:$left = false;
echo $line;
}
else if ($right)
{
$line = ($i % 2 == 0 && $j == $space) ? " ":" 3 ";
($j == $end) ? $mid = true:"";
$rightCount = 0;
$leftCount = 1;
echo $line;
}
}
echo "<br>";
}
please need help to improve my code, so i can get print like first output
question from:
https://stackoverflow.com/questions/65909662/php-maze-generator-with-looping 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…