diff --git a/Week 4/D2 - 2 b/Week 4/D2 - 2 index 9624875..8f51ec1 100644 --- a/Week 4/D2 - 2 +++ b/Week 4/D2 - 2 @@ -26,11 +26,11 @@ int is_valid_dir(char *array, int index, int dir) { } } -bool is_stuck(char *arr, int index) { - return !(*(arr + index + up) == '.' || - *(arr + index + down) == '.' || - *(arr + index + left) == '.' || - *(arr + index + right) == '.' +int is_stuck(char *arr, int index) { + return !(is_valid_dir(arr, index, up) || + is_valid_dir(arr, index, down) || + is_valid_dir(arr, index, left) || + is_valid_dir(arr, index, right) ); } @@ -38,17 +38,15 @@ int main() { srand(time(0)); // seed rand int direction[4] = {-10, -1, 10, 1}; // to convert rand output to a position change // generate maze - char maze_[10][10] = {}; - + char maze[10][10] = {}; for (int i = 0; i < 10; i++) { // the 2d way for (int j = 0; j < 10; j++) { - maze_[i][j] = '.'; + maze[i][j] = '.'; } } - char *maze = &maze_; char character = 'A'; int pos = 0; - maze[pos] = character; + maze[0][0] = character; // traverse maze for (int i = 0; i < 25; i++) { int dir = direction[rand() % 4]; @@ -60,12 +58,14 @@ int main() { break; } pos += dir; - maze[pos] = ++character; + maze[pos / 10][pos % 10] = ++character; } - for (int i = 0; i < 100; i++) { - printf("%c", maze[i]); - if (i % 10 == 9) { - printf("\n"); + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++){ + printf("%c", maze[i][j]); } + printf("\n"); } + } \ No newline at end of file