我正在尝试编写“康威生命游戏”可视化。我想我对如何去做有一个可靠的想法,但我遇到的问题是:当我尝试输出二维数组的行和列时,它开始在数字之间跳跃,并且永远不会停止滚动号码。它似乎被 78 的“x”抓住了。
#include <iostream>
#include <cstring>
#include <cstdlib>
#define HEIGHT 25
#define WIDTH 80
using namespace std;
void makeBoard();
int seed = 0;
int main()
{
makeBoard();
}
void makeBoard()
{
int board[79][24] = {0};
/* Seed the random number generator with the specified seed */
srand(seed);
for(int x = 0; x <= 79; x++)
{
for(int y = 0; y <= 24; y++)
{
/* 50% chance for a cell to be alive */
if(rand() % 100 < 50)
{
board[x][y] = {1};
}
else
{
board[x][y] = {0};
}
/*if(board[x][y] == 1) {
cout << "SPAM" << endl;
}*/
//this is just printing out the current location it is iterating through.
cout << "X: " << x << " Y: " << y << endl;
}
cout << endl;
}
}
运行它所需的所有代码都应该在那里。
感谢您的帮助和耐心。