Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include "pch.h"
  2. #include <fstream>
  3. #include <iostream>
  4. void zawiniecie(int (&siatka)[14][22])
  5. {
  6. for (int s = 0; s != 14; s++)
  7. for (int ss = 0; ss != 22; ss++)
  8. {
  9. if (s == 0 || s == 13 || ss == 0 || ss == 21)
  10. {
  11. if (s == 0)
  12. siatka[0][ss] = siatka[12][ss];
  13. else if (s == 13)
  14. siatka[13][ss] = siatka[1][ss];
  15. else if (ss == 0)
  16. siatka[s][0] = siatka[s][20];
  17. else if (ss == 21)
  18. siatka[s][21] = siatka[s][1];
  19. }
  20. }
  21. siatka[13][21] = siatka[1][1];
  22. siatka[0][0] = siatka[12][20];
  23. siatka[13][0] = siatka[1][20];
  24. siatka[0][21] = siatka[12][1];
  25. }
  26. void pokolenia(int (&siateczka)[14][22])
  27. {
  28.  
  29. int ilosc, g1, h1, pok[14][22];
  30. for (int z = 0; z != 14; z++)
  31. for (int x = 0; x != 22; x++)
  32. pok[z][x] = siateczka[z][x];
  33. for (int g = 1; g != 14; g++)
  34. {
  35. for (int h = 1; h != 22; h++)
  36. {
  37. ilosc = 0;
  38. if (siateczka[g][h] == 1)
  39. {
  40. for (g1 = -1; g1 != 2; g1++)
  41. for (h1 = -1; h1 != 2; h1++)
  42. if (siateczka[g + g1][h + h1] == 1)
  43. ilosc++;
  44. if (ilosc == 3 || ilosc == 4)
  45. pok[g][h] = 1;
  46. else
  47. pok[g][h] = 0;
  48. }
  49. else
  50. {
  51. for (g1 = -1; g1 != 2; g1++)
  52. for (h1 = -1; h1 != 2; h1++)
  53. if (siateczka[g + g1][h + h1] == 1)
  54. ilosc++;
  55. if (ilosc == 3)
  56. pok[g][h] = 1;
  57. else
  58. pok[g][h] = 0;
  59. }
  60. }
  61. }
  62. zawiniecie(pok);
  63. for (int z = 0; z != 14; z++)
  64. for (int x = 0; x != 22; x++)
  65. siateczka[z][x] = pok[z][x];
  66. }
  67. int main()
  68. {
  69. std::ifstream dane("gra.txt");
  70. std::ofstream wynik("wynik.txt");
  71. char a;
  72. int plansza[14][22], plansza1[14][22], plansza2[14][22];
  73. for (int q = 0; q != 14; q++)
  74. for (int w = 0; w != 22; w++)
  75. {
  76. if (q == 0 || q == 13 || w == 0 || w == 21)
  77. continue;
  78. dane >> a;
  79. if (a == 'X')
  80. plansza[q][w] = 1;
  81. else
  82. plansza[q][w] = 0;
  83. }
  84. zawiniecie(plansza);
  85. for (int q = 1; q != 13; q++)
  86. {
  87. for (int w = 1; w != 21; w++)
  88. std::cout << plansza[q][w] << " ";
  89. std::cout << std::endl;
  90. }
  91. for (int h = 0; h != 36; h++)
  92. pokolenia(plansza);
  93. std::cout << std::endl << std::endl;
  94. for (int q = 1; q != 13; q++)
  95. {
  96. for (int w = 1; w != 21; w++)
  97. std::cout << plansza[q][w] << " ";
  98. std::cout << std::endl;
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement