Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <fstream>
- #include <iostream>
- void zawiniecie(int (&siatka)[14][22])
- {
- for (int s = 0; s != 14; s++)
- for (int ss = 0; ss != 22; ss++)
- {
- if (s == 0 || s == 13 || ss == 0 || ss == 21)
- {
- if (s == 0)
- siatka[0][ss] = siatka[12][ss];
- else if (s == 13)
- siatka[13][ss] = siatka[1][ss];
- else if (ss == 0)
- siatka[s][0] = siatka[s][20];
- else if (ss == 21)
- siatka[s][21] = siatka[s][1];
- }
- }
- siatka[13][21] = siatka[1][1];
- siatka[0][0] = siatka[12][20];
- siatka[13][0] = siatka[1][20];
- siatka[0][21] = siatka[12][1];
- }
- void pokolenia(int (&siateczka)[14][22])
- {
- int ilosc, g1, h1, pok[14][22];
- for (int z = 0; z != 14; z++)
- for (int x = 0; x != 22; x++)
- pok[z][x] = siateczka[z][x];
- for (int g = 1; g != 14; g++)
- {
- for (int h = 1; h != 22; h++)
- {
- ilosc = 0;
- if (siateczka[g][h] == 1)
- {
- for (g1 = -1; g1 != 2; g1++)
- for (h1 = -1; h1 != 2; h1++)
- if (siateczka[g + g1][h + h1] == 1)
- ilosc++;
- if (ilosc == 3 || ilosc == 4)
- pok[g][h] = 1;
- else
- pok[g][h] = 0;
- }
- else
- {
- for (g1 = -1; g1 != 2; g1++)
- for (h1 = -1; h1 != 2; h1++)
- if (siateczka[g + g1][h + h1] == 1)
- ilosc++;
- if (ilosc == 3)
- pok[g][h] = 1;
- else
- pok[g][h] = 0;
- }
- }
- }
- zawiniecie(pok);
- for (int z = 0; z != 14; z++)
- for (int x = 0; x != 22; x++)
- siateczka[z][x] = pok[z][x];
- }
- int main()
- {
- std::ifstream dane("gra.txt");
- std::ofstream wynik("wynik.txt");
- char a;
- int plansza[14][22], plansza1[14][22], plansza2[14][22];
- for (int q = 0; q != 14; q++)
- for (int w = 0; w != 22; w++)
- {
- if (q == 0 || q == 13 || w == 0 || w == 21)
- continue;
- dane >> a;
- if (a == 'X')
- plansza[q][w] = 1;
- else
- plansza[q][w] = 0;
- }
- zawiniecie(plansza);
- for (int q = 1; q != 13; q++)
- {
- for (int w = 1; w != 21; w++)
- std::cout << plansza[q][w] << " ";
- std::cout << std::endl;
- }
- for (int h = 0; h != 36; h++)
- pokolenia(plansza);
- std::cout << std::endl << std::endl;
- for (int q = 1; q != 13; q++)
- {
- for (int w = 1; w != 21; w++)
- std::cout << plansza[q][w] << " ";
- std::cout << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement