Update 'Week 4/D2 - 2'
This commit is contained in:
parent
7b108cc087
commit
5f76559543
@ -26,11 +26,11 @@ int is_valid_dir(char *array, int index, int dir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_stuck(char *arr, int index) {
|
int is_stuck(char *arr, int index) {
|
||||||
return !(*(arr + index + up) == '.' ||
|
return !(is_valid_dir(arr, index, up) ||
|
||||||
*(arr + index + down) == '.' ||
|
is_valid_dir(arr, index, down) ||
|
||||||
*(arr + index + left) == '.' ||
|
is_valid_dir(arr, index, left) ||
|
||||||
*(arr + index + right) == '.'
|
is_valid_dir(arr, index, right)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,17 +38,15 @@ int main() {
|
|||||||
srand(time(0)); // seed rand
|
srand(time(0)); // seed rand
|
||||||
int direction[4] = {-10, -1, 10, 1}; // to convert rand output to a position change
|
int direction[4] = {-10, -1, 10, 1}; // to convert rand output to a position change
|
||||||
// generate maze
|
// generate maze
|
||||||
char maze_[10][10] = {};
|
char maze[10][10] = {};
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) { // the 2d way
|
for (int i = 0; i < 10; i++) { // the 2d way
|
||||||
for (int j = 0; j < 10; j++) {
|
for (int j = 0; j < 10; j++) {
|
||||||
maze_[i][j] = '.';
|
maze[i][j] = '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char *maze = &maze_;
|
|
||||||
char character = 'A';
|
char character = 'A';
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
maze[pos] = character;
|
maze[0][0] = character;
|
||||||
// traverse maze
|
// traverse maze
|
||||||
for (int i = 0; i < 25; i++) {
|
for (int i = 0; i < 25; i++) {
|
||||||
int dir = direction[rand() % 4];
|
int dir = direction[rand() % 4];
|
||||||
@ -60,12 +58,14 @@ int main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pos += dir;
|
pos += dir;
|
||||||
maze[pos] = ++character;
|
maze[pos / 10][pos % 10] = ++character;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 100; i++) {
|
|
||||||
printf("%c", maze[i]);
|
for (int i = 0; i < 10; i++) {
|
||||||
if (i % 10 == 9) {
|
for (int j = 0; j < 10; j++){
|
||||||
printf("\n");
|
printf("%c", maze[i][j]);
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user