Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- void printfile( FILE *file ) {
- if ( file != NULL ) {
- rewind( file );
- int c = fgetc( file );
- while ( c != EOF ) {
- printf( "%c", c );
- c = fgetc( file );
- }
- }
- printf("\n");
- rewind( file );
- }
- void inspect_maze_matrix( char array[][9] ) {
- printf("[\n");
- for( int i = 0; i < 9; i++ ) {
- printf(" [ ");
- for( int j = 0; j < 9; j++ ) {
- printf( "%c ", array[i][j] );
- }
- printf("]\n");
- }
- printf("]\n");
- }
- void fill_maze_matrix( char array[][9] ) {
- FILE *maze_file = fopen( "data.txt", "r" );
- // printfile( maze_file );
- int x = 0;
- int y = 0;
- char c = fgetc( maze_file );
- while ( c != EOF ) {
- if ( c == *"X" ) {
- array[x][y] = *"X";
- y++;
- } else if ( c == *"Y" ) {
- array[x][y] = *"Y";
- y++;
- } else if ( c == *"\n" ) {
- x++;
- y = 0;
- }
- c = fgetc( maze_file );
- }
- fclose( maze_file );
- }
- typedef struct {
- int x;
- int y;
- } Position;
- typedef struct {
- } PositionStack;
- void print_position( Position *pos ) {
- printf( "current position: x:%d y:%d\n", pos->x, pos->y );
- }
- bool valid_position( Position *pos ) {
- if (
- pos->x < 9 &&
- pos->x >= 0 &&
- pos->y < 9 &&
- pos->y >= 0
- ) {
- return true;
- } else {
- return false;
- }
- }
- bool search( char array[][9], Position *current_pos ) {
- if ( current_pos->x == 8 && current_pos->y == 0 ) {
- print_position( current_pos );
- return true;
- } else {
- if ( array[ current_pos->x ][ current_pos->y ] != *"Y" ) {
- return false;
- } else {
- print_position( current_pos );
- Position below = { current_pos->x + 1, current_pos->y };
- Position above = { current_pos->x - 1, current_pos->y };
- Position left = { current_pos->x, current_pos->y - 1 };
- Position right = { current_pos->x, current_pos->y + 1 };
- if ( valid_position( &below ) && search( array, &below ) ) {
- return true;
- }
- else if ( valid_position( &left ) && search( array, &left ) ) {
- return true;
- }
- else {
- return false;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment