Guest User

Untitled

a guest
Jul 21st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. //Matriz.h
  6. class Matriz{
  7.     private:
  8.         bool **datos;
  9.     public:
  10.         int filas;
  11.         int columnas;
  12.         Matriz(int f, int c, bool valor);
  13.         void mostrar(bool mostrarEjes);
  14.         void set(int fila, int columna, bool valor);
  15.         bool get(int fila, int columna);
  16.         bool tocaBorde(int fila, int columna);
  17.         ~Matriz();
  18.     };
  19. /////////
  20.  
  21. //Matriz.cpp
  22. Matriz::Matriz(int f, int c, bool valor){
  23.     filas = f;
  24.     columnas = c;
  25.     datos = new bool *[filas];
  26.     for(int i=0; i<filas; i++){
  27.         datos[i] = new bool[columnas];
  28.         for (int j=0; j<columnas; j++){
  29.             datos[i][j] = valor;
  30.             }
  31.         }
  32.     }
  33.    
  34. void Matriz::mostrar(bool mostrarEjes){
  35.     for(int i=0; i<filas; i++){
  36.         if (mostrarEjes) {cout << i << "| ";}
  37.         for(int j=0; j<columnas; j++){
  38.             cout << datos[i][j] << " ";
  39.             }
  40.         cout << endl;
  41.         }
  42.        
  43.     if (mostrarEjes){
  44.         cout << "   ";
  45.         for (int j=0;j<columnas;j++){
  46.             cout << "__";
  47.             }
  48.         cout << endl;
  49.  
  50.         cout << "   ";
  51.         for (int j=0;j<columnas;j++){
  52.             cout << j << " ";
  53.             }
  54.         cout << endl;
  55.         }
  56.     }
  57.    
  58. void Matriz::set(int fila, int columna, bool valor){
  59.     datos[fila][columna] = valor;
  60.     }
  61.    
  62. bool Matriz::get(int fila, int columna){
  63.     return datos[fila][columna];
  64.     }
  65.    
  66. bool Matriz::tocaBorde(int fila, int columna){
  67.     if ((fila == 0) or (fila == filas-1) or (columna == 0) or (columna == columnas-1)){
  68.         return true;
  69.         }
  70.     else{
  71.         return false;
  72.         }
  73.     }
  74.        
  75. Matriz::~Matriz(){
  76.     for(int i=0; i<filas; i++){
  77.         for (int j=0; j<columnas; j++){
  78.             delete datos[j];
  79.             }
  80.         }
  81.     delete datos;
  82.     }
  83. /////////
  84.  
  85. void mostrarMensaje(string mensaje, bool saltoDeLinea){
  86.     /* Imprime un mensaje en consola con o sin salto de linea. */
  87.     if (saltoDeLinea){
  88.         cout << mensaje << endl;
  89.         }
  90.     else {
  91.         cout << mensaje;
  92.         }
  93.     }
  94.  
  95. void mostrarDatosAlumno(){
  96.     /* Imprime en pantalla datos generales. */
  97.     mostrarMensaje("TP2 - RUTAS",1);
  98.     mostrarMensaje("Alumno: Castro Pippo, Juan Manuel",1);
  99.     mostrarMensaje("Padron: 93760",1);
  100.     mostrarMensaje("-----------------------------------------",1);
  101.     mostrarMensaje("",1);
  102.     }
  103.  
  104. string tipoCamino(bool tipo){
  105.     /* Devuelve un string con el tipo de Camino. */
  106.     string tipoCamino;
  107.     if (tipo == 0) {tipoCamino = ".";}
  108.     else {
  109.         if (tipo == 1) {tipoCamino = "X";}
  110.         }
  111.     return tipoCamino;
  112.     }
  113.  
  114. //void solicitarDatosMatriz(bool mapa[MAX_LADO][MAX_LADO], int *lado){
  115.     /* Solicita los datos necesarios al usuario para generar la matriz. */
  116.     /*bool datoCelda;
  117.     mostrarMensaje("GENERAR MAPA: INGRESE 0 (Tierra) y 1 (Asfalto)",1);
  118.     for (int i=0;i<*lado;i++){
  119.         for (int j=0;j<*lado;j++){
  120.             cin >> datoCelda;
  121.             mapa[i][j] = datoCelda;
  122.         }
  123.     }
  124. }*/
  125.  
  126. bool tocaBorde(bool mapa, int *nFilas, int *nCol, int fila, int col){
  127.     return true;
  128.     //if (fila == 0) or (fila == *lado-1) or (col == 0) or (col == *lado-1)
  129.     }
  130.  
  131. int nBaldozasToca(bool mapa, int *nFilas, int *nCol, int fila, int col){
  132.     return 0;
  133.     }
  134.  
  135. void set_ls_baldozas (int ls_baldozas[4][2], int n, int fila, int col){
  136.     ls_baldozas[n][0] = fila;
  137.     ls_baldozas[n][1] = col;
  138.     }
  139.  
  140. short int get_lenght_baldozasCircundantes(int ls_baldozas[4][2]){
  141.     short int cantidad = 0;
  142.     for(int i=0;i<4;i++) {
  143.         if ((ls_baldozas[i][0]!=-1) && (ls_baldozas[i][1]!=-1)){
  144.             cantidad+=1;
  145.             }
  146.         }
  147.     return cantidad;
  148.     }
  149.  
  150. void encontrarSiguienteBaldoza(int ls_baldozas[4][2], int baldoza[2], Matriz mapa, int fila_descarte, int col_descarte){
  151.     /*Revisa la lista ls_baldozas y descartando la baldoza ya pisada por descarte obtiene la siguiente*/
  152.     for(int i=0;i<4;i++) {
  153.         if ((ls_baldozas[i][0]!=-1) && (ls_baldozas[i][1]!=-1)){
  154.             if ((ls_baldozas[i][0]!=fila_descarte) || (ls_baldozas[i][1]!=col_descarte)){
  155.                 baldoza[0] = ls_baldozas[i][0];
  156.                 baldoza[1] = ls_baldozas[i][1];
  157.                 }
  158.             }
  159.         }
  160.    
  161.     }
  162.  
  163. void baldozasCircundantes(/*int ls_baldozas[4][2], */Matriz mapa, int fila, int col){
  164.     /*Genera una lista con la ubicacion de las baldozas de Asfalto, el resto las deja en [-1][-1] */
  165.     mostrarMensaje("baldozasCircundantes-1",1);
  166.     //int n = 0;
  167.     //Reseteo lista de baldozas
  168.     //for(int i=0;i<4;i++) {set_ls_baldozas(ls_baldozas,i,-1,-1);}
  169.     /*mostrarMensaje("baldozasCircundantes-2",1);
  170.     cout << fila << " fila " << col << " col" << endl;
  171.     if ((fila != 0) && (mapa.get(fila-1,col) == 1)){
  172.         mostrarMensaje("baldozasCircundantes-3",1);
  173.         set_ls_baldozas(ls_baldozas,n,fila-1,col);
  174.         n = n+1;
  175.         }
  176.    
  177.    
  178.     if ((fila != mapa.filas-1) && (mapa.get(fila+1,col) == 1)) {
  179.         mostrarMensaje("baldozasCircundantes-4",1);
  180.         //set_ls_baldozas(ls_baldozas,n,fila+1,col);
  181.         cout << mapa.get(0,0) << " mapa.get" << endl;
  182.         mostrarMensaje("baldozasCircundantes-4.1",1);
  183.         //n = n+1;
  184.         }
  185.    
  186.     if ((col != 0) && (mapa.get(fila,col-1) == 1)) {
  187.         mostrarMensaje("baldozasCircundantes-5",1);
  188.         set_ls_baldozas(ls_baldozas,n,fila,col-1);
  189.         n = n+1;
  190.         }
  191.  
  192.     if ((col != mapa.columnas-1) && (mapa.get(fila,col+1) == 1)) {
  193.         mostrarMensaje("baldozasCircundantes-6",1);
  194.         set_ls_baldozas(ls_baldozas,n,fila,col+1);
  195.         n = n+1;
  196.         }
  197.     mostrarMensaje("baldozasCircundantes-7",1);*/
  198.     /*cout << "Lista de Baldozas Circundantes a " << col << "," << fila << " ";
  199.     for(int i=0;i<4;i++){
  200.         cout << "[" << ls_baldozas[i][1] << "," << ls_baldozas[i][0] << "]";
  201.         }
  202.     cout << endl;*/
  203.     }
  204.  
  205. void buscarCentroCamino(Matriz mapa, int fila_act, int col_act, int fila_ant, int col_ant){
  206.     mostrarMensaje("3",1);
  207.     int ls_baldozas[4][2];
  208.     int baldoza[2]={-1,-1};
  209.     //cout << mapa.get(0,0) << ",-T-" << endl;
  210.     //baldozasCircundantes(ls_baldozas,mapa,fila_act,col_act);
  211.     mostrarMensaje("5",1);
  212.     encontrarSiguienteBaldoza(ls_baldozas,baldoza,mapa,fila_ant,col_ant);
  213.     mostrarMensaje("6",1);
  214.     if (get_lenght_baldozasCircundantes(ls_baldozas)==2){
  215.         cout << "[" << col_act << "," << fila_act << "]-";
  216.         buscarCentroCamino(mapa, baldoza[0], baldoza[1], fila_act, col_act);
  217.         }
  218.     else {
  219.         if (mapa.tocaBorde(fila_act, col_act) && (get_lenght_baldozasCircundantes(ls_baldozas)==1)){
  220.             cout << "[" << col_act << "," << fila_act << "]" << endl;
  221.             }
  222.         else{
  223.             cout << " CAMINO FALSO";
  224.             }
  225.         }
  226.     }
  227.  
  228. void buscarInicioCamino(Matriz mapa, int fila, int col){
  229.     mostrarMensaje("buscarInicioCamino-1",1);
  230.     //int ls_baldozas[4][2];
  231.     //ls_baldozas/*[4][2]*/ = {{-1,-1},{-1,-1},{-1,-1},{-1,-1}};
  232.     /*baldozasCircundantes(*//*ls_baldozas,*//*mapa,fila,col);*/
  233.     mostrarMensaje("buscarInicioCamino-1.1",1);
  234.     cout << mapa.get(0,0) << " mapa.get" << endl;
  235.     mostrarMensaje("buscarInicioCamino-2",1);
  236.     if (mapa.tocaBorde(fila, col) /*&& (get_lenght_baldozasCircundantes(ls_baldozas)==1)*/){
  237.         cout << "Camino:  ";
  238.         cout << "[" << col << "," << fila << "]-";
  239.         cout << mapa.get(0,0) << " mapa.get" << endl;
  240.         //buscarCentroCamino(mapa, ls_baldozas[0][0], ls_baldozas[0][1], fila, col);
  241.         }
  242.     //Si es la 1ra pieza debe
  243.     }
  244.  
  245. void encontrarCaminos(Matriz mapa){
  246.     /* Busca los caminos de Asfalto. */
  247.     mostrarMensaje("CAMINOS ENCONTRADOS: ",1);
  248.    
  249.     //Escanea la primer fila
  250.     int j=2;
  251.     /*for (int j=0;j<mapa.columnas;j++){*/
  252.         cout << j << " --mapa.get" << endl;
  253.         cout << mapa.get(0,2) << "erwe" << j << endl;
  254.         if (mapa.get(0,j) == 1){
  255.             mostrarMensaje("encontrarCamino-1",1);
  256.             buscarInicioCamino(mapa,0,j);
  257.             }
  258.         /*}*/
  259.     mostrarMensaje("encontrarCamino-2",1);
  260.     }
  261.    
  262. int main(){
  263.     int nFilas, nCol;
  264.     nFilas = 3;
  265.     nCol = 3;
  266.    
  267.     mostrarDatosAlumno();
  268.     Matriz mapa(nFilas,nCol,false);
  269.     mapa.set(0,1,false);
  270.     mapa.set(1,1,true);
  271.     mapa.set(2,1,true);
  272.     mostrarMensaje("MAPA: ",1);
  273.     mapa.mostrar(true);
  274.     //encontrarCaminos(mapa);
  275.     mostrarMensaje("FIN",1);
  276.     return 0;
  277.     }
Add Comment
Please, Sign In to add comment