예제 #1
0
int main(int argc, char *argv[])
{	
	srand(time(NULL));
	int SDL = 0; 				// SDL flag
	maze_entrance entrance; 	// Stores coords of entrance to maze
	maze_dimensions dimensions; // Stores width and height of the maze as given in file
	max_maze mazeArray; 		// Char array of maximum size
	
	arg_check(argc);

	// Initalise to spaces. In case the user has entered a newline early.
	initialiseArray(mazeArray, MAX_SIZE); 

	// Inspect and act on argv[1]. Get maze from file or generate it.
	dimensions = get_maze(argv, mazeArray);

	// If argv[2] is given, set/don't set graphics flag. Will ignore further arguements.
	if (argc >= 3) {
		SDL = initialise_SDL(argv);
	}
	
	entrance = findEntrance(mazeArray,dimensions);

	if(explore(entrance.x, entrance.y, mazeArray, dimensions)){
		
		printf("Route found!\n\n");

		if(SDL){
			display_SDL(mazeArray, dimensions); // Display solution with SDL GUI
		}
		else {
			display_Terminal(mazeArray, dimensions); // Use the terminal unless told otherwise
		}
		return 0;
	} 
	else { 
		// If unsuccessful, show the scanned maze in terminal regardless of SDL flag:
		printf("No path found through the maze!\nThe maze was scanned as:\n");
		display_Terminal(mazeArray, dimensions);
		
		if(SDL){
			display_SDL(mazeArray, dimensions);
		}

		return 1;
	}
}
예제 #2
0
파일: maze.c 프로젝트: AStadum/C-C-Unix
int main(int argc, const char* argv[])
{
	if( argc != 2 ) //checks for the input file name
	{
		printf( "error; no input file name\n" );
		return 1;
	}

	FILE *filePointer;
	filePointer = fopen( argv[1], "r" );
	char **arrayPointer;


	//char maze[MAX_MAZE_SIZE][MAX_MAZE_SIZE] = { 0 };

	int numberOfTestCases = 0;
	fscanf( filePointer, "%d\n", &numberOfTestCases );

	for( int testCaseNumber = 0; testCaseNumber < numberOfTestCases; testCaseNumber++ )
	{
        int size = 0;
        int * xy;
        int x;
        int y;
		fscanf( filePointer, "%d\n", &size );
		
		printf( "ENTER\n" );
        allocateArray(size, &arrayPointer);
		initializeArray(size, arrayPointer, filePointer);
		xy = findEntrance(size, arrayPointer);
		x = xy[0];
		y = xy[1];
		solveMaze(size, arrayPointer, x ,y);
		deallocateArray(size, arrayPointer);
		printf( "EXIT\n***\n" );		
	}


	fclose( filePointer );
	return 0;
}