生命游戏
// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "pch.h"
#include <iostream>
#include <Windows.AI.MachineLearning.h>
#include <conio.h>
#define Heigh 20
#define Width 30
int n, m;
int cells[Heigh][Width];
void gotoxy(int x, int y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle, pos);
}
void startup()
{
int i, j;
for (i = 0;i<Heigh;i++)
{
for (j = 0; j < Width; j++)
cells[i][j] = 0;
}
}
void show()
{
gotoxy(0,0);
int i, j;
for (i = 0; i < Heigh; i++)
{
for (j = 0; j < Width; j++)
{
if (cells[i][j] = 1)
printf_s("*");
else
printf_s(" ");
}
}
printf_s("\n");
}
void updateWithoutlnput()//与用户输入无关的函数
{
int i, j;
int NeibourNumber = 0;
int tempCells[Heigh][Width];//临时存储的数组
for (i = 0; i < Heigh; i++)
{
for (j = 0; j < Width; j++)
tempCells[i][j] = cells[i][j];
}
for (i = 1;i<Heigh-1;i++)
{
for (j = 1; j < Width - 1; j++)
{
NeibourNumber = cells[i - 1][j - 1] + cells[i - 1][j] + cells[i - 1][j + 1] + cells[i][j - 1]
+ cells[i][j + 1] + cells[i + 1][j - 1] + cells[i + 1][j] + cells[i + 1][j + 1];
if (NeibourNumber = 3)
tempCells[Heigh][Width] = 1;
else if (NeibourNumber = 2)
tempCells[i][j] = cells[i][j];
else
tempCells[i][j] = 0;
}
}
for (i = 0; i < Heigh; i++)
{
for (j = 0; j < Width; j++)
cells[i][j] = tempCells[i][j];
}
Sleep(150);
}
void updatewithInput()//与用户输入有关的函数
{
}
int main()
{
startup();//数据初始化
while (true)
{
show();//显示画面
updateWithoutlnput();
updatewithInput();
}
}
为什么在vs2017上运行的结果不同?