|
![]() | 作者: fatcat [xu09]
![]() |
登录 |
生命游戏的规则:有一个有界的方形网格,每个格中有一细胞,所有细胞按代进行生和死的变化。 每一代的生死状态变化仅与上一代有关。生死变化按如下规则进行: 1~每个细胞按横向,纵向,斜向共有八个邻居; 2~如果某个细胞是活的,但它的邻居只有一个或零个是活的,那么它的下一代将因孤独而死去。 3~如果某个细胞是活的,它有四个或是更多的活邻居,那么它的下一代将因拥挤而死亡。 4~如果某个细胞是活的,并且有两至三个活邻居,那么它的下一代仍然是活的。 5~如果某个细胞是死的,但它正好有三个活邻居,那么它的下一代将复活。其它情况下,本代是死的,下一代仍是死的。 6~每一代的变化都是在同一瞬间进行的。因此某个细胞的死亡或复活都不会对相邻细胞本代的状态产生影响。 请各位朋友帮忙想想这个程序应该怎么编。请指教。。。。。。。。或者哪里有源程序提供下载的,小弟在此谢过!! |
地主 发表时间: 05/20 11:02 |
![]() | 回复: dirboys [dirboys] ![]() |
登录 |
请参阅99年电脑报合订本,或者e-mail我terencetong@263.net,我可以发传真或者e-mail给你详细资料 [此贴被 dirboys(dirboys) 在 5月20日13时3分 编辑过] |
B1层 发表时间: 5/20 13:8 |
![]() | 回复: fatcat [xu09] ![]() |
登录 |
好的, 谢谢! 我的邮箱是xu09@163.com |
B2层 发表时间: 05/21 07:22 |
![]() | 回复: dirboys [dirboys] ![]() |
登录 |
已经寄给你了 |
B3层 发表时间: 05/21 09:58 |
![]() | 回复: dirboys [dirboys] ![]() |
登录 |
#include<graphics.h> main(){ int orgData[100][100],resData[100][100]; int nCount,nRows,nCols,i,j,times; int GraphDriver=DETECT,GraphMode; for (i=0;i<100;i++) for(j=0;j<100;j++) orgData[i][j]=1; initgraph(&GraphDriver,&GraphMode,""); setcolor(WHITE); rectangle(270,190,370,290); for(times=1;times<200;times++){ for(nRows=1;nRows<99;nRows++){ for(nCols=1;nCols<99;nCols++){ nCount=orgData[nRows-1][nCols-1]+orgData[nRows-1][nCols]+orgData[nRows-1][nCols+1]+orgData[nRows][nCols-1]+orgData[nRows][nCols+1]+orgData[nRows+1][nCols-1]+orgData[nRows+1][nCols]+orgData[nRows+1][nCols+1]; switch(nCount){ case 3: putpixel(nCols+210,120+nRows, BLACK); resData[nRows][nCols]=1;break; case 2: resData[nRows][nCols]=orgData[nRows][nCols];break; default:resData[nRows][nCols]=0; putpixel(nCols+210,120+nRows,WHITE); } } } for(i=1;i<99;i++) for(j=1;j<99;j++) orgData[i][j]=resData[i][j]; } } |
B4层 发表时间: 05/21 10:59 |
![]() | 回复: fatcat [xu09] ![]() |
登录 |
谢谢了。。。。 只是这里的有些函数还是看不懂, 能不能给我讲解一下呢?~~~~~~ |
B5层 发表时间: 05/21 21:29 |
![]() | 回复: snake [snake] ![]() |
登录 |
1。一个细胞集团。起初2个 2。一小时死一个 3。其它的分解为2个 4。结束的条件是N个 ?????????????????? |
B6层 发表时间: 05/22 06:46 |
![]() | 回复: dirboys [dirboys] ![]() |
登录 |
1。这是模仿了100*100个细胞的变异情况。 2。起初他们都是活的(用白色表现) 3。ncount计算了周围8个细胞的情况 4。switch按ncount的条件判断,默认(default)情况下细胞为死亡 5。如果细胞死了,就用黑色表现 6。由于这种细胞变异可以一直进行下去,所以只取值times=200,如果修改可以显示更多变化 7。有其他问题请继续,也欢迎高手优化 |
B7层 发表时间: 05/22 09:24 |
![]() | 回复: fatcat [xu09] ![]() |
登录 |
#include <graphics.h> #include <stdio.h> #include <stdlib.h> #include <dos.h> #include <bios.h> #include <conio.h> static int sz[20][20][2]; void huatu() {void mouse(int x,int y); int i,j; for (i=0;i<20;i++) for (j=0;j<20;j++) {sz[i][j][1]=0; sz[i][j][0]=0;} cleardevice(); setviewport(0,0,640,480,1); clearviewport(); setbkcolor(0); setcolor(62); setlinestyle(0,0,3); rectangle(0,0,480,478); for (i=0;i<20;i++) line(24*i,0,24*i,480); for (j=0;j<20;j++) line(0,24*j,480,24*j); setcolor(4); rectangle(494,0,638,478); setcolor(3); rectangle(498,4,634,474); settextstyle(1,0,4); setcolor(4); outtextxy(502,40,"Y alive"); outtextxy(502,80,"N dady"); outtextxy(556,120,"down"); outtextxy(556,200,"up"); outtextxy(556,160,"right"); outtextxy(556,240,"left"); settextstyle(1,1,3); outtextxy(498,104,"-"); outtextxy(498,117,"-"); outtextxy(498,120,"<"); outtextxy(498,200,"-"); outtextxy(498,187,"-"); outtextxy(498,184,">"); outtextxy(513,273,"-"); settextstyle(1,0,3); outtextxy(502,160,"-"); outtextxy(512,160, " "); outtextxy(515,160,">"); outtextxy(502,240,"<"); outtextxy(505,240,"-"); outtextxy(515,240,"-"); outtextxy(502,280,"<"); outtextxy(505,280,"-"); outtextxy(515,280,"-"); mouse(0,0); } outtext1(int l1,int l2,int l3) { char s1[10],s2[10],s3[10]; setfillstyle(1,60); bar(580,430,622,456); setfillstyle(1,1); bar(580,386,622,414); setfillstyle(1,57); bar(580,342,622,370); settextjustify(0,0); settextstyle(1,0,3); sprintf(s1,"%d",l1); sprintf(s2,"%d",l2); sprintf(s3,"%d",l3); outtextxy(584,410,s1); outtextxy(584,452,s2); outtextxy(584,366,s3); } void mouse(int x,int y) {setcolor(RED); setfillstyle(1,RED); bar(24*x+8,24*y+8,24*x+16,24*y+16); } void qiaomouse(int x,int y) {setcolor(0); setfillstyle(1,0); bar(24*x+8,24*y+8,24*x+16,24*y+16); } void yuan(int x,int y) {setcolor(2); setlinestyle(0,0,3); circle(x*24+12,y*24+12,8); /*floodfill(x*32+16,y*24+12,4);*/} void qiaoyuan(int x,int y) {setcolor(0); setlinestyle(0,0,3); circle(x*24+12,y*24+12,8);} int get_key() {union REGS rg; rg.h.ah=0; int86(0x16,&rg,&rg); return rg.h.ah;} void huamouse() {int x=0,x0=0,y=0,y0=0,key=0; while(1) {key=0; while(bioskey(1)==0); key=get_key(); if (key==0x15) {yuan(x,y);sz[x][y][0]=1; if (x==19) { if (y==19){x0=x;y0=y;y=0;x=0;} else{x0=x;x=0;y0=y;y=y+1;} } else {x0=x;y0=y;x=x+1;} } if (key==0x31) {qiaoyuan(x,y);sz[x][y][0]=0; if (x==19) {x0=x;x=0;y0=y;y=y+1;} else {x0=x;y0=y;x=x+1;} } if (key==0x48) {if (y==0) {y0=y;x0=x;y=15;} else {y0=y;x0=x;y=y-1;} } if (key==0x4b) {if (x==0){x0=x;y0=y;x=19;} else {x0=x;y0=y;x=x-1;} } if (key==0x4d) {if (x==19){x0=x;y0=y;x=0;} else {x0=x;y0=y;x=x+1;} } if (key==0x50) {if (y==19) {y0=y;x0=x;y=0;} else {y0=y;x0=x;y=y+1;} } qiaomouse(x0,y0); mouse(x,y); if (key==28) break; } qiaomouse(x,y); } void bijiao() {int i,j,k; for (i=0;i<20;i++) for (j=0;j<20;j++) {k=0; {if ((i-1>=0)&&(j-1>=0)&&(sz[i-1][j-1][0]==1)) k=k+1; if ((j-1>=0)&&(sz[i][j-1][0]==1)) k=k+1; if ((i+1<20)&&(j+1)<20&&(sz[i+1][j+1][0]==1)) k=k+1; if ((i+1<20)&&(sz[i+1][j][0]==1)) k=k+1; if ((i+1<20)&&(j-1>=0)&&(sz[i+1][j-1][0]==1)) k=k+1; if ((i-1>=0)&&(j+1<20)&&(sz[i-1][j+1][0]==1)) k=k+1; if ((i-1>=0)&&(sz[i-1][j][0]==1)) k=k+1; if ((j+1<20)&&(sz[i][j+1][0]==1)) k=k+1;} {if(k==0||k==1) sz[i][j][1]=0; if (k==2&&sz[i][j][0]==1) sz[i][j][1]=1; if (k==3) sz[i][j][1]=1; if (k>3)sz[i][j][1]=0;} } } void swap() {int i,j; for (i=0;i<20;i++) for (j=0;j<20;j++) {sz[i][j][0]=sz[i][j][1]; sz[i][j][1]=0;} } void bianhua(int l3) {int i,j,l1=0,l2=0,key; while(l1<l3) {key=get_key(); if (key==0x51) {bijiao(); for (i=0;i<20;i++) for (j=0;j<20;j++) { if (sz[i][j][0]==1) qiaoyuan(i,j); if (sz[i][j][1]==1){l2++;yuan(i,j);} } swap(); l1++; outtext1(l1,l2,l3);l2=0; } } } void sutoxy(int x,int y) {union REGS regs; {regs.h.ah=2; regs.h.dh=y; regs.h.dl=x; regs.h.bh=0; int86(0x10,®s,®s); }} int caidan1() {int l; cleardevice(); setcolor(2); settextstyle(1,0,3); outtextxy(195,200,"Welcome to you!"); outtextxy(195,236,"Please input..."); sutoxy(46,15); scanf("%d",&l); return(l); } int caidan2() {int l,key; setfillstyle(1,60); bar(180,190,430,280); setcolor(RED);setlinestyle(0,0,3); rectangle(183,193,427,277); setcolor(2); settextstyle(1,0,3); outtextxy(195,220,"Are you continue?"); outtextxy(265,260,"(y/n)"); while(1) {key=0; key=get_key(); if (key==21){return(1);} if (key==0x31) {return(0);}} } main1() {int graphdriver=VGA,graphmode=VGAHI; int l1=0,l2=0,l3=0; initgraph(&graphdriver,&graphmode,""); do{l3=caidan1(); huatu(); outtext1(l1,l2,l3); huamouse(); bianhua(l3);} while(caidan2()); closegraph();} 程序有些不完整还请教。。。 |
B8层 发表时间: 05/24 15:46 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号