C语言--生命细胞游戏 小弟第二次编程,希望大神帮忙指点
C语言--生命细胞游戏 小弟第二次编程。找了很久,都没有找出问题,不管我输入什么数字,输出的结果都还是@,希望大神帮忙指点/*
File name :Life Game.C
Description:Game of life implementation
生命细胞游戏
*/
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#define MAXROW 10
#define MAXCOL 25
#define alive 1
#define dead 0
int map[MAXROW][MAXCOL],newmap[MAXROW][MAXCOL];
int Generation=0;
void init();
int Neighbour(int,int);
void output_map();
void copymap();
void main()
{
int row,col;
char ans;
init();
output_map();
do
{
for(row=0;row<MAXROW;row++)
for(col=0;col<MAXCOL;col++)
switch (Neighbour(row,col))
{
case 0:
case 1:
case 4:
case 5:
case 6:
case 7:
case 8:newmap[row][col]=dead;
break;
case 2:newmap[row][col]=map[row][col];
break;
case 3:newmap[row][col]=alive;
break;
}
copymap();
do
{
printf("\n Continue Next Generation?");
ans=toupper(getche());
if(ans=='Y'||ans=='N')
break;
}while(1);
if(ans=='Y') output_map();
}while(ans=='Y');
}
void init()
{
int row,col;
for(row=0;row<MAXROW;row++)
for(col=0;col<MAXCOL;col++)
map[row][col]=dead;
printf("初始化成功\n");
printf("Game Of Life Program \n");
printf("Enter (x,y) where (x,y) is a living cell\n");
printf("0<=x<%d,0<=y<%d\n",MAXROW,MAXCOL);
printf("Terminate with (x,y) =(-1,-1)\n");
do
{
scanf("%d%d",&row,&col);
if(row<0||row>=MAXROW||col<0||col>=MAXCOL)
printf("(x,y) exceeds map ranage!\n");
else
map[row][col]=alive;
}while(row!=-1||col!=-1);
}
int Neighbour(int row,int col)
{
int i,j,count=0;
for(i=row-1;i<=row+1;i++)
for(j=col-1;j<col+1;j++)
{
if(i<0||i>=MAXROW||j<0||j>=MAXROW)
continue;
if(map[i][j]==alive)
count++;
}
if(map[row][col]==alive)
count--;
return count;
}
void output_map()
{
int row,col;
printf("\n\n%24c Game of Life cell status\n",' ');
printf("%24Cc--------Generation %d----------\n",++Generation);
for(row=0;row<MAXROW;row++)
{
printf("\n%20c",' ');
for(col=0;col<MAXCOL;col++)
{
if(map[row][col]=dead)
printf("%2c",'-');
else
printf("%2c",'@');
}
}
}
void copymap()
{
int row,col;
for(row=0;row<MAXROW;row++)
for(col=0;col<MAXCOL;col++)
map[row][col]=newmap[row][col];
}