-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapa.h
More file actions
104 lines (59 loc) · 1.59 KB
/
Mapa.h
File metadata and controls
104 lines (59 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef __TAREA__
#define __TAREA__
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
/*
XXXXXXXXXXXXXXXXX
x.......x..t....x
xXXX...t....xxxxx
xXXX...t....xxxxx
xXXXXXXXXXXXXXXXX
*/
vector<pair<int, int>> direcciones = { {0,1},{0,-1},{-1,0},{1,0} };
bool limitado(vector<vector<char> >& T, int i, int j) { /*determinar si el agente o el robot esta dentro de los limites del map*/
return i >= 0 and j >= 0 and i< int(T.size()) and j < int(T[0].size());
}
bool dfs(vector<vector<char> >& T, int i, int j) { /*recibe mapa*/
/*CASO BASE*/
if (T[i][j] == 't') {
return true;
}
else if (T[i][j] == 'X') {
return false;
}
// Moverme en el mapa
for (auto& d : direcciones) {
int adj_i = i + d.first;
int adj_j = j + d.second;
// (adj_i,adj_j) nueva posicion casilla
if (limitado(T, adj_i, adj_j) and dfs(T, adj_i, adj_j))
return true;
}
return false; // No he sido capaz de llegar a ningún tesoro
}
void mapa() {
int n, m; //vertices y aristas
int r, c; //son x,y las coordenadas donde se encuentra el agente
bool respuesta_algoritmo;
vector<vector<char> > T(n, vector<char>(m)); /*Cree el mapa de caracteres*/
/*inicializacion del mapa*/
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> T[i][j];
}
}
cout << "Digite las coordenadas del agente::";
cin >> r >> c;
/*algoritmo dfs*/
respuesta_algoritmo = dfs(x, y, z);
if (respuesta_algoritmo) {
cout << "Encontro un tesoro en el mapa";
}
else {
cout << "No se encuentra el tesoro en el mapa";
}
}
#endif // !__GRAFOS__