小编r23*_*333的帖子

通过迷宫找到所有可能的路径

我正在尝试创建一个程序,它将遍历一个随机生成的迷宫,其中1是开放的,0是墙.从左上角开始到右下角结束.路径可以向上,向下,向左和向右.

目前,我的程序给了我一个解决方案,但我无法让它打印多个路径.

我已经阅读了这个问题的几个不同版本,但我无法找到一个与我的参数相当的版本.

这是我的代码,我省略了随机生成迷宫的部分.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>

int  n, minMatrix, solIndex = 1, minLen = 10000000; //I use the latter 3 variables in order to find the shortest path, not relevant for now


bool solveMaze(int mat[n][n],int x, int y, int sol[][n], int count){

int i, j;
  if((!(x >= 0 && x <n  && y >=0 && y < n)) || mat[x][y] == 0 || sol[x][y] == 1){
    return false;
  }

  if(x == n-1 && y …
Run Code Online (Sandbox Code Playgroud)

maze

7
推荐指数
1
解决办法
1470
查看次数

标签 统计

maze ×1