#include #include #include #include char map[100][100]; int visited[100][100]; int counter = 0; bool isDrafty(int x, int y) { // Determines whether there's a trap in the immediate vicinity of the square we're standing on return (map[y][x] == '.' && (map[y+1][x] == 'T' || map[y-1][x] == 'T' || map[y][x+1] == 'T' || map[y][x-1] == 'T')); } void move(int mx, int my, int w, int h) { // Moves our x, y by 1 until a wall is found or becomes drafty char c = map[my][mx]; // Avoid visiting visited nodes(endless loop occurs) if (visited[my][mx]) { return ; } visited[my][mx] = true; // Stop if drafty or wall. Increment counter if gold is found. if (c == '#') { return ; } // printf("x: %d, y: %d, c: %c\n", mx, my, c); if (c == 'G') { counter++; } if(c == 'T' || isDrafty(mx, my)){ return ; } // 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