= 0 && $i <= $max-1) && ($j >= 0 && $j <= $max-1)) { //var_dump("yesss"); $queue[$rear] = array($nodes => $move); } //var_dump($queue);die; return $queue; } function deQueue($queue , $front) { return $queue[$front]; } function shortestPath($n, $i_start, $j_start, $i_end, $j_end) { $front = $rear = 0; $queue = array(); $queue = enqueue($queue , $rear , $i_start.",".$j_start , "" , $n); $rear++; while ($front < $rear) { $node = deQueue($queue , $front); $front++; foreach($node as $key => $value) { $data = $key; $move = $value; break; } $arrNode = explode("," , $data); $i = $arrNode[0]; $j = $arrNode[1]; if ($i == $i_end && $j == $j_end) { return $node[$data]; } $queue = enqueue($queue , $rear , ($i-2).",".($j-1) , $move." UL" , $n); $rear++; $queue = enqueue($queue , $rear , ($i-2).",".($j+1) , $move." UR" , $n); $rear++; $queue = enqueue($queue , $rear , ($i).",".($j+2) , $move." R" , $n); $rear++; $queue = enqueue($queue , $rear , ($i+2).",".($j+1) , $move." LR" , $n); $rear++; $queue = enqueue($queue , $rear , ($i+2).",".($j-1) , $move." LL" , $n); $rear++; $queue = enqueue($queue , $rear , ($i).",".($j-2) , $move." L" , $n); $rear++; } return "Impossible"; } fscanf($handle, "%i",$n); fscanf($handle, "%i %i %i %i", $i_start, $j_start, $i_end, $j_end); $x = printShortestPath($n, $i_start, $j_start, $i_end, $j_end); //var_dump($x); ?>