Example #1
0
int main()
{
	int nrow_map = 0, ncol_map = 0;
	const char *filename = "D:\\data\\map.txt";
	int **maze;
	int **mark;
	TCellPtr pstack;

	if(!verify_mat(filename, &nrow_map, &ncol_map)){
		printf("请检查迷宫地图文件:文件读取失败,或地图每行的元素数目不相容\n");
		exit(0);
	}

	// 读入地图文件
	maze = read_map(filename, nrow_map, ncol_map);
	// 生成迷宫访问标记矩阵
	mark = setup_mat(nrow_map, ncol_map);
	// 初始化路径探测堆栈
	pstack = setup_stack(nrow_map, ncol_map);

	search_maze( maze, mark, pstack, nrow_map, ncol_map );


	// 销毁为存储迷宫地图而动态分配的内存
	destroy_map(maze, nrow_map);
	// 销毁为存储迷宫访问标记而动态分配的内存
	destroy_map(mark, nrow_map);
	// 销毁路径探测堆栈
	free(pstack);

	system("pause");
	return 0;
}
Example #2
0
void show_route(int **maze, TCellPtr pstack, int nrow, int ncol, int top)
{
	int i, j;
	int choice = 1; // 用于保存输出选项 
	int ** newmap = setup_mat( nrow, ncol); //newmap[][]存放迷宫的出路路径图中的迷宫单元 
	for(i = 0; i < nrow; i++)  
		for( j = 0; j < ncol; j++)
			newmap[i][j] = GWALL;  // 采用字符“#”填充整个迷宫

	while(choice)
	{
		printf("\n请选择显示方式:\n  1.显示原始迷宫图\n  2.显示迷宫出路路径坐标\n  3.显示迷宫出路模拟图\n  0.结束游戏\n");
		printf("\n请选择相应的数字: ");
		scanf_s("%d", &choice);
		getchar();

		switch(choice){    //选择显示方式			
		case 0:
			break;
		case 1:
			show_map(maze, nrow, ncol);
			break;
		case 2:
			{
				printf("\n迷宫出路路径为:");     //输出出路路径
				printf("\n行\t列");
				for( i = 0; i <= top; i++)
					printf("\n%d\t%d", pstack[i].row, pstack[i].col);
				printf("\n%d\t%d",nrow, ncol);
				//choice = 0;
				break;
			}
		case 3:
			{
				// 采用符号“-”填充与路径相对应的迷宫单元
				for( i = 0; i <= top; i++){
					newmap[pstack[i].row][pstack[i].col] = GPATH;
				}
				newmap[nrow - 2][ncol - 2] = GPATH; // 填充出口单元

				printf("\n迷宫的出路模拟显示图形如下\n");
				//输出迷宫穿越路线图
				for(i = 0; i < nrow; i++) {  
					for( j = 0; j < ncol; j++){
						printf("%c ", newmap[i][j]);
					}
					printf("\n");
				}
				break;
			}
		default:
			{
				printf("输入错误,请重新输入!\n");
				scanf_s("%d", &choice);
			}
		}//switch(choice)
	}//while(choice)
	destroy_map(newmap,  nrow); // 回收为迷宫地图分配的内存空间
}
Example #3
0
File: setup.c Project: GCZhang/SNAP
/*******************************************************************************
 * Control the setup process
 *******************************************************************************/
void setup ( input_data *input_vars, para_data *para_vars, time_data *time_vars,
             geom_data *geom_vars, sn_data *sn_vars, data_data *data_vars,
             solvar_data *solvar_vars, control_data *control_vars,
             mms_data *mms_vars, FILE *fp_out, int *ierr, char **error )
{
/*******************************************************************************
 * Local variables
 *******************************************************************************/
    int flg, mis, mie, mjs, mje, mks, mke, qis, qie, qjs, qje, qks, qke;

    double t1, t2;

 /*******************************************************************************
 *  First put input ny and nz into ny_gl and nz_gl respectively. Use ny
 *  and nz for local sizes. Determine global indices of local bounds.
 *  Establish min of nthreads and ng for threaded MPI calls in sweep.
 *******************************************************************************/
    t1 = wtime();

    NY_GL = NY;
    NZ_GL = NZ;

    NY = NY_GL / NPEY;
    NZ = NZ_GL / NPEZ;

    JLB =  YPROC      * NY + 1;
    JUB = (YPROC + 1) * NY;
    KLB =  ZPROC      * NZ + 1;
    KUB = (ZPROC + 1) * NZ;

    NUM_GRTH = MIN( NTHREADS, NG );

/*******************************************************************************
 *  Allocate needed arrays
 *******************************************************************************/
    setup_alloc( input_vars, para_vars, sn_vars, data_vars, &flg, ierr, error );

    if ( *ierr != 0 )
    {
        print_error ( fp_out, *error, IPROC, ROOT );

        stop_run( flg, 0, 0, para_vars, sn_vars, data_vars, mms_vars,
                   geom_vars, solvar_vars, control_vars );
    }

/*******************************************************************************
 *  Progress through setups. _delta sets cell and step sizes, _vel sets
 *  velocity array, _angle sets the ordinates/weights, _mat sets the
 *  material identifiers, _src sets fixed source, _data sets the
 *  mock cross section arrays, and expcoeff sets up the scattering
 *  expansion basis function array.
 *******************************************************************************/
    setup_delta( input_vars, geom_vars, control_vars );

    setup_vel( input_vars, data_vars );

    setup_angle( input_vars, sn_vars );

    setup_mat( input_vars, geom_vars, data_vars,
               &mis, &mie, &mjs, &mje, &mks, &mke );

    setup_data( input_vars, data_vars );

    expcoeff( input_vars, sn_vars, &NDIMEN );

    setup_src( input_vars, para_vars, geom_vars, sn_vars, data_vars, control_vars,
               mms_vars, &qis, &qie, &qjs, &qje, &qks, &qke, ierr, error );

    if ( *ierr != 0 )
    {
        print_error ( fp_out, *error, IPROC, ROOT );

        stop_run( 2, 0, 0, para_vars, sn_vars, data_vars, mms_vars,
                   geom_vars, solvar_vars, control_vars );
    }

/*******************************************************************************
 *  Echo the data from this module to the output file. If requested via
 *  scatp, print the full scattering matrix to file.
 *******************************************************************************/
    if ( IPROC == ROOT )
    {
        setup_echo ( fp_out, input_vars, para_vars, geom_vars, data_vars, sn_vars,
                     control_vars, mis, mie, mjs, mje, mks, mke,
                     qis, qie, qjs, qje, qks, qke );

        if ( SCATP == 1 ) setup_scatp( input_vars, para_vars, data_vars, ierr, error );
    }

    glmax_i ( ierr, COMM_SNAP );

    if ( *ierr != 0 )
    {
        print_error ( fp_out, *error, IPROC, ROOT );

        FREE ( error );

        stop_run ( 3, 0, 0, para_vars, sn_vars, data_vars, mms_vars,
                   geom_vars, solvar_vars, control_vars );
    }

    t2 = wtime();
    TSET = t2 - t1;
}