массивы — Game of Life Stack Overflow

Привет, я в настоящее время делаю программу, которая находит количество «живых» клеток после того, как пройдены определенные поколения. Входы:

• первая строка, правила игры, указанные выше. то есть: B3 / S23 = Ячейка «родилась», если у нее ровно 3 соседа, «Выживает», если у нее 2 или 3 живых соседа; иначе умирает.

• вторая строка, число i — количество итераций, которые должна пройти игра.

• третья строка, 2 числа — количество строк (n) и столбцов (m) на доске.

• n строк (строк) по m (столбцов) символов в каждой. Все символы «#» или «.»

Наконец, доска является тороидальной. то есть левая и правая стороны обертывают вокруг, а нижняя и верхняя стороны обертывают вокруг.
И с моими кодами я получаю кучу ошибок, о которых я даже не знаю … Плюс я даже не знаю, правильно ли я делаю … Не могли бы вы, ребята, помогите мне.

#include<iostream>
#include<string>
#include <vector>
using namespace std;
// other includes? Probably yes.
void copy(int m, int n, int array1[m][n], int array2[m][n]){
for(int j = 0; j < m; j++;){
for(int i = 0; i < n; i++)
array2[j][i] = array1[j][i];
}
}
void life(int array[m][n], m, n, string born, survive){
//Copies the main array to a temp array so changes can be entered into a grid
//without effecting the other cells and the calculations being performed on them.
int temp[m][n];
copy(array, temp);
for(int j = 1; j <= m; j++){
for(int i = 1; i <= n; i++) {
//The Moore neighborhood checks all 8 cells surrounding the current cell in the array.
int count = 0;
count = array[j-1][i] +
array[j-1][i-1] +
array[j][i-1] +
array[j+1][i-1] +
array[j+1][i] +
array[j+1][i+1] +
array[j][i+1] +
array[j-1][i+1];

//The cell dies.
for(int k = 0; k < born.length(); k++;){
if(count == born[k])
temp[j][i] = 1;
}
for(int x = 0; x < survive.length(); x++;){
if(count != survive[k])
temp[j][i] = 0;
if(count == x)
temp[j][i] = array[j][i];
}
}
}
copy(temp, array);
}
bool compare(int array1[m][n], int array2[m][n])
{
int count = 0;
for(int j = 0; j < m; j++)
{
for(int i = 0; i < n; i++)
{
if(array1[j][i]==array2[j][i])
count++;
}
}
//Since the count gets incremented every time the cells are exactly the same,
//an easy way to check if the two arrays are equal is to compare the count to
//the dimensions of the array multiplied together.
if(count == m*n)
return true;
else
return false;
}
// functions? Yep, there should be some.

int main(){
string variable;
string i;
string grid;
string board;
getline(cin,variable);
getline(cin,i);
getline(cin,grid);
getline(cin,board);
auto pos_b= variable.find_first_of("B");
auto pos_s= variable.find_first_of("S");
pos_s -= pos_b;//now it's the length of size
auto b = variable.substr(pos_b+1,pos_s-2);
auto s = variable.substr(pos_s+1);
int int_b = stoi(b);
int int_s = stoi(s);

cout << int_b << ' ' << int_s << endl;
auto pos_spc= grid.find_first_of(' ');
int row = stoi(grid.substr(0,pos_spc));
int column = stoi(grid.substr(pos_spc+1));
cout << row << ' ' << column << endl;

int cnt = 0;
int gen0[column][row];
int todo[column][row];
int backup[column][row];
for(int j = 1; j < m; j++){
for (int i = 1; i < n; i++){
if(board[j][i] == '.')
board[j][i] = 0;
if(board[j][i] == '#')
board[j][i] = 1;
}
for(int k = 0; k < i; i++){
if(i == 0)
copy(gen0, todo, column,row);
copy(todo, backup,column,row);
print(todo);
life(int todo[column][row], column, row, string int_b, int_s);
cnt++;
}
}
}

Тестовые случаи[контрольные примеры] [2]контрольные примеры

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector