#define EMPTY_CELL ' '
#define CLAIM_CELL '#'
#include <cstdio>
#include <windows.h> //смешная библиотека, ничего не понимаю
const int cols = 5, rows = 5;
const bool isInfinit = true;
int steps = 25;
const int delayTime = 1000;
void Log(const char* msg) {
printf(msg);
printf("\n");
}// а
void LogPrefers() {
printf("PREFERS: \n");
printf("\t cols %d\n", cols);
printf("\t rows %d\n", rows);
printf("\t infinity %d\n", isInfinit);
printf("\t steps %d\n", steps);
printf("\t delay %d\n", delayTime);
}
int main(int argc, char* argv[]) {
// Initialize simulation field
LogPrefers();
Log("Start initializing <?");
char** field = new char* [cols];
for (size_t i = 0; i < cols; ++i) {
field[i] = new char[rows];
}
Log("Memory initialized <!");
Log("Initializing by fill <?");
for (size_t i = 0; i < cols; ++i) {
for (size_t k = 0; k < rows; ++k) {
field[i][k] = ' ';
}
}
field[2][2] = '#';
Log("Memory initialized <!");
Log("Start simulation <?");
Log("Started <!");
// Simulation
do {
int temp = 0;
for (size_t i = 0; i < cols; ++i) {
for (size_t k = 0; k < rows; ++k) { // Господи, заработай пожалуйста с первого раза, аминь
// Проверка соседей вокруг клетки.
if (field[i - 1][k - 1] != NULL && field[i - 1][k - 1] == CLAIM_CELL) temp += 1;
else if (field[i][k - 1] != NULL && field[i - 1][k - 1] == CLAIM_CELL) temp += 1;
else if (field[i + 1][k - 1] != NULL && field[i - 1][k - 1] == CLAIM_CELL) temp += 1;
else if (field[i - 1][k] != NULL && field[i - 1][k - 1] == CLAIM_CELL) temp += 1;
else if (field[i + 1][k] != NULL && field[i - 1][k - 1] == CLAIM_CELL) temp += 1;
else if (field[i + 1][k + 1] != NULL && field[i - 1][k - 1] == CLAIM_CELL) temp += 1;
else if (field[i][k + 1] != NULL && field[i - 1][k - 1] == CLAIM_CELL) temp += 1;
else if (field[i - 1][k + 1] != NULL && field[i - 1][k - 1] == CLAIM_CELL) temp += 1;
if (temp == 3 || temp == 2) {
field[i][k] == '#';
}
else {
field[i][k] == ' ';
}
temp = 0; // Сбрасываем счётчик!111
}
}
for (size_t i = 0; i < cols; ++i) {
printf("\n");
for (size_t k = 0; k < rows; ++k) {
printf("%c", field[i][k]);
}
}
steps -= 1;
//Sleep(delayTime);
} while (steps > 0 || isInfinit);
// Free ramm from simulation field linux suck
Log("! END !");
for (int i = 0; i < cols; ++i) {
delete[] field[i];
}
delete[] field;
return 0;
}
for (int nx = max(0, x-1); nx < min(x+2, n); ++nx) {
for (int ny = max(0, y-1); ny < min(y+2, n); ++ny) {
if (nx == x && ny == y) continue;
// {nx, ny} - сосед в поле, обрабатываем его.
}
}
for (int nx = x-1; nx <= x+1; ++nx) {
for (int ny = y-1; ny <= y+1; ++ny) {
if ((nx == x && ny == y) || nx < 0 || ny < 0 || nx >= n || ny >= n) continue;
// {nx, ny} - соседняя клетка.
}
}