-1
我正在寫康威的人生遊戲。代碼運行完美,但在控制檯窗口運行後,會寫入「The」clear「命令拼寫錯誤或找不到 。」我不明白這一點。爲什麼發生這種情況?我如何解決清除命令?康威的人生遊戲錯誤
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
void copy(int array1[10][10], int array2[10][10])
{
for(int j = 0; j < 10; j++)
{
for(int i = 0; i < 10; i++)
array2[j][i] = array1[j][i];
}
}
void life(int array[10][10], char choice)
{
int temp[10][10];
copy(array, temp);
for(int j = 0; j < 10; j++)
{
for(int i = 0; i < 10; i++)
{
if(choice == 'm')
{
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];
if(count < 2 || count > 3)
temp[j][i] = 0;
if(count == 2)
temp[j][i] = array[j][i];
if(count == 3)
temp[j][i] = 1;
}
}
}
copy(temp, array);
}
bool compare(int array1[10][10], int array2[10][10])
{
int count = 0;
for(int j = 0; j < 10; j++)
{
for(int i = 0; i < 10; i++)
{
if(array1[j][i]==array2[j][i])
count++;
}
}
if(count == 10*10)
return true;
else
return false;
}
void print(int array[10][10])
{
for(int j = 0; j < 10; j++)
{
for(int i = 0; i < 10; i++)
{
if(array[j][i] == 1)
cout << '*';
else
cout << ' ';
}
cout << endl;
}
}
int main()
{
int gen0[10][10];
int todo[10][10];
int backup[10][10];
char neighborhood;
char again;
char cont;
bool comparison;
string decoration;
do
{
do
{
cout << "Which neighborhood would you like to use (m): ";
cin >> neighborhood;
}while(neighborhood != 'm');
system("clear");
int i = 0;
do
{
srand(time(NULL));
for(int j = 0; j < 10; j++)
{
for (int i = 0; i < 10; i++)
gen0[j][i] = rand() % 2;
}
if(i == 0)
copy(gen0, todo);
copy(todo, backup);
print(todo);
life(todo, neighborhood);
i++;
system("sleep .5");
if(i % 10 == 1 && i != 1)
{
cout << endl;
do
{
cout << "Would you like to continue this simulation? (y/n): ";
cin >> cont;
}while(cont != 'y' && cont != 'n');
if(cont == 'n')
break;
}
comparison = compare(todo, backup);
if(comparison == false)
system("clear");
if(comparison == true)
cout << endl;
}while(comparison == false);
do
{
cout << "Would you like to run another simulation? (y/n): ";
cin >> again;
}while(again != 'y' && again != 'n');
}while(again == 'y');
return 0;
}
我想這取決於你要運行它的OS /控制檯上。你的操作系統是什麼,你使用的是什麼外殼? – Hayt