74 lines
1.2 KiB
C
Raw Permalink Normal View History

2023-12-01 13:35:13 +01:00
0
0023.0
3.
9.8__auto_type
// Avoid visiting visited nodes(endless loop occurs)
if (visited[my][mx]) {
return ;
}
visited[my][mx] = true;
31 7
// Stop if drafty or wall. Increment counter if gold is found.
if (c == '#') {
return ;
}
if(c == 'T'){
return ;
= 0
// printf("x: %d, y: %d, c: %c\n", mx, my, c);
if (c == 'G') {
counter++;
}
// Move (as long as we're not stepping out of bounds)
if (mx < w) {
move(mx+1, my, w, h); //Right
}
if (my < h) {
move(mx, my+1, w, h); // Up
}
if (mx > 0) {
move(mx-1, my, w, h); //Left
}
if (my > 0) {
move(mx, my-1, w, h); // Down
}
return ;
}
int main(int argc, char **argv) {
int w, h;
scanf("%d %d", &w, &h);
int px, py;
// Populate map
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
scanf(" %c", &map[i][j]);
// Set player coordinates
if (map[i][j] == 'P') {
py = i;
px = j;
}
}
}
for (int i=0; i < 100; i++) {
for(int j=0; j < 100; j++) {
visited[i][j] = false;
}
}
// Initiate traversal
move(px, py, w, h);
// Print result
printf("%d\n", counter);
return 0;
}