Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: michfere43 en 27 Octubre 2020, 23:58 pm



Título: Torre de Hanoi
Publicado por: michfere43 en 27 Octubre 2020, 23:58 pm
Hola si me pueden ayudar , necesito hacer el juego de las torres de hanoi pero me falta el metodo de apilar y desapilar
Código
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int iniciarJuego(int torre1[], int torre2[], int torre3[], int cima1, int discos);
  6. void mostrarTorres(int torre1[], int torre2[], int torre3[], int discos);
  7. void mostrarCima(int cima1, int cima2, int cima3);
  8.  
  9.  
  10. int main()
  11. {
  12. cout<<"T O R R E  D E  H A N O I"<<endl<<endl;
  13. int discos = 0;
  14. cout<<"Para iniciar indica el numero de discos: ";
  15. cin>>discos;
  16.  
  17.  
  18. int torre1[discos];
  19. int cima1 = -1;
  20. int torre2[discos];
  21. int cima2 = -1;
  22. int torre3[discos];
  23. int cima3 = -1;
  24. int opc = 0;
  25. int origen = 0;
  26. int destino = 0;
  27.  
  28. cima1 = iniciarJuego(torre1, torre2, torre3, cima1, discos);
  29. //mostrarTorres(torre1, torre2, torre3, discos);
  30. //mostrarCima(cima1, cima2, cima3);
  31. if(discos==1)
  32. {
  33. cout<<"mover disco de torre 1 a torre 3" ;
  34. }
  35. else
  36. {
  37. cout<<"Selecciona una opcion: \n 1. Realizar un movimiento\n 2. Terminar el juego";
  38. cin>>opc;
  39. switch(opc)
  40. {
  41. case 1:
  42. cout<<endl<<endl<<"Torre origen: ";
  43. cin>>origen;
  44. void moverdisco();
  45. switch(origen)
  46. {
  47. case 1:
  48. cout<<endl<<"Torre destino: \n 2. Torre 2\n 3. Torre 3"<<endl;
  49. cin>>destino;
  50. if(destino == 2 || destino == 3)
  51. {
  52. void desapilar();
  53. }else{
  54. cout<<endl<<"Torre destino invalido"<<endl;
  55. }
  56. break;
  57. case 2:
  58. cout<<endl<<"Torre destino: \n 1. Torre 1\n 3. Torre 3"<<endl;
  59. cin>>destino;
  60. break;
  61. case 3:
  62. cout<<endl<<"Torre destino: \n 2. Torre 2\n 1. Torre 1"<<endl;
  63. cin>>destino;
  64. break;
  65. default:
  66. cout<<endl<<"Torre destino invalido"<<endl;
  67. break;
  68. }
  69. break;
  70. case 2:
  71. break;
  72. default:
  73. cout<<endl<<"Torre origen invalido"<<endl;
  74. opc = 3;
  75. break;
  76. }
  77. }while(opc == 3);
  78.  
  79.  
  80. return 0;
  81. }
  82.  
  83. int iniciarJuego(int torre1[], int torre2[], int torre3[], int cima1, int discos)
  84. {
  85. for(int i = 0; i<discos; i ++)
  86. {
  87. torre1[i] = discos - i;
  88. cima1 ++;
  89.  
  90. torre2[i] = 0;
  91. torre3[i] = 0;
  92. }
  93.  
  94. return cima1;
  95. }
  96.  
  97. void mostrarTorres(int torre1[], int torre2[], int torre3[], int discos)
  98. {
  99. cout<<endl<<"Torre 1: ";
  100. for (int i = 0; i<discos; i++)
  101. {
  102. cout<<torre1[i]<<" ";
  103. }
  104.  
  105. cout<<endl<<"Torre 2: ";
  106. for (int i = 0; i<discos; i++)
  107. {
  108. cout<<torre2[i]<<" ";
  109. }
  110.  
  111. cout<<endl<<"Torre 3: ";
  112. for (int i = 0; i<discos; i++)
  113. {
  114. cout<<torre3[i]<<" ";
  115. }
  116. }
  117.  
  118. void mostrarCima(int cima1, int cima2, int cima3)
  119. {
  120. cout<<endl<<endl<<"Indice cima 1: "<<cima1;
  121. cout<<endl<<"Indice cima 2: "<<cima2;
  122. cout<<endl<<"Indice cima 3: "<<cima3;
  123. }
  124.  
  125. void desapilar()
  126. {
  127.  
  128. }
  129. void apilar()
  130. {
  131.  
  132. }

MOD: Etiquetas GeSHi.


Título: Re: Torre de Hanoi
Publicado por: K-YreX en 29 Octubre 2020, 01:33 am
Explica qué tienen que hacer esas funciones de la forma más detallada posible.

Ya habrás visto que poniendo ahí todo el programa y las dos funciones que te faltan, totalmente en blanco no estás recibiendo muchas respuestas.

Además supongo que de alguna manera sabrás empezar, no? No esperes que te hagan las funciones enteras. Empieza a hacerlo a tu manera y detalla la parte en la que tengas problemas.