=0 && $move[0]<$n && $move[1]>=0 && $move[1]<$n && !isset($visitedCache[$move[0]][$move[1]]) ){ $end++; $coordX[$end] = $move[0]; $coordY[$end] = $move[1]; $moves[$end] = $currentMoves; $steps[$end] = $currentSteps; $visitedCache[$move[0]][$move[1]] = true; } $currentMoves = @$moves[$start]; $currentSteps = @$steps[$start]; $move = [$i-2, $j+1]; $currentMoves .="UR "; $currentSteps++; if (checkCoords($move[0], $move[1], $i_end, $j_end)){ echo $currentSteps."\r\n"; echo trim($currentMoves)."\r\n"; die(); } /* If not matched, we add them to the BFS array */ if ($move[0]>=0 && $move[0]<$n && $move[1]>=0 && $move[1]<$n && !isset($visitedCache[$move[0]][$move[1]]) ){ $end++; $coordX[$end] = $move[0]; $coordY[$end] = $move[1]; $moves[$end] = $currentMoves; $steps[$end] = $currentSteps; $visitedCache[$move[0]][$move[1]] = true; } $currentMoves = @$moves[$start]; $currentSteps = @$steps[$start]; $move = [$i, $j+2]; $currentMoves .="R "; $currentSteps++; if (checkCoords($move[0], $move[1], $i_end, $j_end)){ echo $currentSteps."\r\n"; echo trim($currentMoves)."\r\n"; die(); } /* If not matched, we add them to the BFS array */ if ($move[0]>=0 && $move[0]<$n && $move[1]>=0 && $move[1]<$n && !isset($visitedCache[$move[0]][$move[1]]) ){ $end++; $coordX[$end] = $move[0]; $coordY[$end] = $move[1]; $moves[$end] = $currentMoves; $steps[$end] = $currentSteps; $visitedCache[$move[0]][$move[1]] = true; } $currentMoves = @$moves[$start]; $currentSteps = @$steps[$start]; $move = [$i+2, $j+1]; $currentMoves .="LR "; $currentSteps++; if (checkCoords($move[0], $move[1], $i_end, $j_end)){ echo $currentSteps."\r\n"; echo trim($currentMoves)."\r\n"; die(); } /* If not matched, we add them to the BFS array */ if ($move[0]>=0 && $move[0]<$n && $move[1]>=0 && $move[1]<$n && !isset($visitedCache[$move[0]][$move[1]]) ){ $end++; $coordX[$end] = $move[0]; $coordY[$end] = $move[1]; $moves[$end] = $currentMoves; $steps[$end] = $currentSteps; $visitedCache[$move[0]][$move[1]] = true; } $currentMoves = @$moves[$start]; $currentSteps = @$steps[$start]; $move = [$i+2, $j-1]; $currentMoves .="LL "; $currentSteps++; if (checkCoords($move[0], $move[1], $i_end, $j_end)){ echo $currentSteps."\r\n"; echo trim($currentMoves)."\r\n"; die(); } /* If not matched, we add them to the BFS array */ if ($move[0]>=0 && $move[0]<$n && $move[1]>=0 && $move[1]<$n && !isset($visitedCache[$move[0]][$move[1]]) ){ $end++; $coordX[$end] = $move[0]; $coordY[$end] = $move[1]; $moves[$end] = $currentMoves; $steps[$end] = $currentSteps; $visitedCache[$move[0]][$move[1]] = true; } $currentMoves = @$moves[$start]; $currentSteps = @$steps[$start]; $move = [$i, $j-2]; $currentMoves .="L "; $currentSteps++; if (checkCoords($move[0], $move[1], $i_end, $j_end)){ echo $currentSteps."\r\n"; echo trim($currentMoves)."\r\n"; die(); } /* If not matched, we add them to the BFS array */ if ($move[0]>=0 && $move[0]<$n && $move[1]>=0 && $move[1]<$n && !isset($visitedCache[$move[0]][$move[1]]) ){ $end++; $coordX[$end] = $move[0]; $coordY[$end] = $move[1]; $moves[$end] = $currentMoves; $steps[$end] = $currentSteps; $visitedCache[$move[0]][$move[1]] = true; } $moves[$start] = null; $start++; //echo "$start , $end \r\n"; } echo "Impossible"; } fscanf($handle, "%i",$n); fscanf($handle, "%i %i %i %i", $i_start, $j_start, $i_end, $j_end); printShortestPath($n, $i_start, $j_start, $i_end, $j_end); ?>