Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //Matriz.h
- class Matriz{
- private:
- bool **datos;
- public:
- int filas;
- int columnas;
- Matriz(int f, int c, bool valor);
- void mostrar(bool mostrarEjes);
- void set(int fila, int columna, bool valor);
- bool get(int fila, int columna);
- bool tocaBorde(int fila, int columna);
- ~Matriz();
- };
- /////////
- //Matriz.cpp
- Matriz::Matriz(int f, int c, bool valor){
- filas = f;
- columnas = c;
- datos = new bool *[filas];
- for(int i=0; i<filas; i++){
- datos[i] = new bool[columnas];
- for (int j=0; j<columnas; j++){
- datos[i][j] = valor;
- }
- }
- }
- void Matriz::mostrar(bool mostrarEjes){
- for(int i=0; i<filas; i++){
- if (mostrarEjes) {cout << i << "| ";}
- for(int j=0; j<columnas; j++){
- cout << datos[i][j] << " ";
- }
- cout << endl;
- }
- if (mostrarEjes){
- cout << " ";
- for (int j=0;j<columnas;j++){
- cout << "__";
- }
- cout << endl;
- cout << " ";
- for (int j=0;j<columnas;j++){
- cout << j << " ";
- }
- cout << endl;
- }
- }
- void Matriz::set(int fila, int columna, bool valor){
- datos[fila][columna] = valor;
- }
- bool Matriz::get(int fila, int columna){
- return datos[fila][columna];
- }
- bool Matriz::tocaBorde(int fila, int columna){
- if ((fila == 0) or (fila == filas-1) or (columna == 0) or (columna == columnas-1)){
- return true;
- }
- else{
- return false;
- }
- }
- Matriz::~Matriz(){
- for(int i=0; i<filas; i++){
- for (int j=0; j<columnas; j++){
- delete datos[j];
- }
- }
- delete datos;
- }
- /////////
- void mostrarMensaje(string mensaje, bool saltoDeLinea){
- /* Imprime un mensaje en consola con o sin salto de linea. */
- if (saltoDeLinea){
- cout << mensaje << endl;
- }
- else {
- cout << mensaje;
- }
- }
- void mostrarDatosAlumno(){
- /* Imprime en pantalla datos generales. */
- mostrarMensaje("TP2 - RUTAS",1);
- mostrarMensaje("Alumno: Castro Pippo, Juan Manuel",1);
- mostrarMensaje("Padron: 93760",1);
- mostrarMensaje("-----------------------------------------",1);
- mostrarMensaje("",1);
- }
- string tipoCamino(bool tipo){
- /* Devuelve un string con el tipo de Camino. */
- string tipoCamino;
- if (tipo == 0) {tipoCamino = ".";}
- else {
- if (tipo == 1) {tipoCamino = "X";}
- }
- return tipoCamino;
- }
- //void solicitarDatosMatriz(bool mapa[MAX_LADO][MAX_LADO], int *lado){
- /* Solicita los datos necesarios al usuario para generar la matriz. */
- /*bool datoCelda;
- mostrarMensaje("GENERAR MAPA: INGRESE 0 (Tierra) y 1 (Asfalto)",1);
- for (int i=0;i<*lado;i++){
- for (int j=0;j<*lado;j++){
- cin >> datoCelda;
- mapa[i][j] = datoCelda;
- }
- }
- }*/
- bool tocaBorde(bool mapa, int *nFilas, int *nCol, int fila, int col){
- return true;
- //if (fila == 0) or (fila == *lado-1) or (col == 0) or (col == *lado-1)
- }
- int nBaldozasToca(bool mapa, int *nFilas, int *nCol, int fila, int col){
- return 0;
- }
- void set_ls_baldozas (int ls_baldozas[4][2], int n, int fila, int col){
- ls_baldozas[n][0] = fila;
- ls_baldozas[n][1] = col;
- }
- short int get_lenght_baldozasCircundantes(int ls_baldozas[4][2]){
- short int cantidad = 0;
- for(int i=0;i<4;i++) {
- if ((ls_baldozas[i][0]!=-1) && (ls_baldozas[i][1]!=-1)){
- cantidad+=1;
- }
- }
- return cantidad;
- }
- void encontrarSiguienteBaldoza(int ls_baldozas[4][2], int baldoza[2], Matriz mapa, int fila_descarte, int col_descarte){
- /*Revisa la lista ls_baldozas y descartando la baldoza ya pisada por descarte obtiene la siguiente*/
- for(int i=0;i<4;i++) {
- if ((ls_baldozas[i][0]!=-1) && (ls_baldozas[i][1]!=-1)){
- if ((ls_baldozas[i][0]!=fila_descarte) || (ls_baldozas[i][1]!=col_descarte)){
- baldoza[0] = ls_baldozas[i][0];
- baldoza[1] = ls_baldozas[i][1];
- }
- }
- }
- }
- void baldozasCircundantes(/*int ls_baldozas[4][2], */Matriz mapa, int fila, int col){
- /*Genera una lista con la ubicacion de las baldozas de Asfalto, el resto las deja en [-1][-1] */
- mostrarMensaje("baldozasCircundantes-1",1);
- //int n = 0;
- //Reseteo lista de baldozas
- //for(int i=0;i<4;i++) {set_ls_baldozas(ls_baldozas,i,-1,-1);}
- /*mostrarMensaje("baldozasCircundantes-2",1);
- cout << fila << " fila " << col << " col" << endl;
- if ((fila != 0) && (mapa.get(fila-1,col) == 1)){
- mostrarMensaje("baldozasCircundantes-3",1);
- set_ls_baldozas(ls_baldozas,n,fila-1,col);
- n = n+1;
- }
- if ((fila != mapa.filas-1) && (mapa.get(fila+1,col) == 1)) {
- mostrarMensaje("baldozasCircundantes-4",1);
- //set_ls_baldozas(ls_baldozas,n,fila+1,col);
- cout << mapa.get(0,0) << " mapa.get" << endl;
- mostrarMensaje("baldozasCircundantes-4.1",1);
- //n = n+1;
- }
- if ((col != 0) && (mapa.get(fila,col-1) == 1)) {
- mostrarMensaje("baldozasCircundantes-5",1);
- set_ls_baldozas(ls_baldozas,n,fila,col-1);
- n = n+1;
- }
- if ((col != mapa.columnas-1) && (mapa.get(fila,col+1) == 1)) {
- mostrarMensaje("baldozasCircundantes-6",1);
- set_ls_baldozas(ls_baldozas,n,fila,col+1);
- n = n+1;
- }
- mostrarMensaje("baldozasCircundantes-7",1);*/
- /*cout << "Lista de Baldozas Circundantes a " << col << "," << fila << " ";
- for(int i=0;i<4;i++){
- cout << "[" << ls_baldozas[i][1] << "," << ls_baldozas[i][0] << "]";
- }
- cout << endl;*/
- }
- void buscarCentroCamino(Matriz mapa, int fila_act, int col_act, int fila_ant, int col_ant){
- mostrarMensaje("3",1);
- int ls_baldozas[4][2];
- int baldoza[2]={-1,-1};
- //cout << mapa.get(0,0) << ",-T-" << endl;
- //baldozasCircundantes(ls_baldozas,mapa,fila_act,col_act);
- mostrarMensaje("5",1);
- encontrarSiguienteBaldoza(ls_baldozas,baldoza,mapa,fila_ant,col_ant);
- mostrarMensaje("6",1);
- if (get_lenght_baldozasCircundantes(ls_baldozas)==2){
- cout << "[" << col_act << "," << fila_act << "]-";
- buscarCentroCamino(mapa, baldoza[0], baldoza[1], fila_act, col_act);
- }
- else {
- if (mapa.tocaBorde(fila_act, col_act) && (get_lenght_baldozasCircundantes(ls_baldozas)==1)){
- cout << "[" << col_act << "," << fila_act << "]" << endl;
- }
- else{
- cout << " CAMINO FALSO";
- }
- }
- }
- void buscarInicioCamino(Matriz mapa, int fila, int col){
- mostrarMensaje("buscarInicioCamino-1",1);
- //int ls_baldozas[4][2];
- //ls_baldozas/*[4][2]*/ = {{-1,-1},{-1,-1},{-1,-1},{-1,-1}};
- /*baldozasCircundantes(*//*ls_baldozas,*//*mapa,fila,col);*/
- mostrarMensaje("buscarInicioCamino-1.1",1);
- cout << mapa.get(0,0) << " mapa.get" << endl;
- mostrarMensaje("buscarInicioCamino-2",1);
- if (mapa.tocaBorde(fila, col) /*&& (get_lenght_baldozasCircundantes(ls_baldozas)==1)*/){
- cout << "Camino: ";
- cout << "[" << col << "," << fila << "]-";
- cout << mapa.get(0,0) << " mapa.get" << endl;
- //buscarCentroCamino(mapa, ls_baldozas[0][0], ls_baldozas[0][1], fila, col);
- }
- //Si es la 1ra pieza debe
- }
- void encontrarCaminos(Matriz mapa){
- /* Busca los caminos de Asfalto. */
- mostrarMensaje("CAMINOS ENCONTRADOS: ",1);
- //Escanea la primer fila
- int j=2;
- /*for (int j=0;j<mapa.columnas;j++){*/
- cout << j << " --mapa.get" << endl;
- cout << mapa.get(0,2) << "erwe" << j << endl;
- if (mapa.get(0,j) == 1){
- mostrarMensaje("encontrarCamino-1",1);
- buscarInicioCamino(mapa,0,j);
- }
- /*}*/
- mostrarMensaje("encontrarCamino-2",1);
- }
- int main(){
- int nFilas, nCol;
- nFilas = 3;
- nCol = 3;
- mostrarDatosAlumno();
- Matriz mapa(nFilas,nCol,false);
- mapa.set(0,1,false);
- mapa.set(1,1,true);
- mapa.set(2,1,true);
- mostrarMensaje("MAPA: ",1);
- mapa.mostrar(true);
- //encontrarCaminos(mapa);
- mostrarMensaje("FIN",1);
- return 0;
- }
Add Comment
Please, Sign In to add comment