24小时热门版块排行榜    

查看: 1530  |  回复: 3
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

chrislan625

新虫 (小有名气)

[求助] 求大神教MATLAB 生命游戏代码怎么写

老师叫我们自学 上课就要写出一个生命游戏的代码 看不太懂 以下是老师给的提示

Skeleton program
function game_of_life( nx, ny, nstep )
%GAME_OF_LIFE Implements the Conway game of life
%   This function implements the Conway game of life in which beings are
%   generated and destroyed in a manner meant to represent evolution. They
%   are destroyed when they have too few or two many neighbours, and are
%   generated at a location with the right number of neighbours.
%
%   Input parameters
%   nx    The number of squares along the x-direction
%   ny    The number of squares along the y-direction
%   nstep The number of iterations in the game
%
%   Output parameters
%   None
%
%
%   Define some constants
delay = 0.1; % The time between images in seconds
dx = [-1,  0,  1, -1,  1, -1,  0,  1];
dy = [ 1,  1,  1,  0,  0, -1, -1, -1];
%
%   Initialise the grid
world = zeros(nx+2, ny+2); % Extra sites around the edge fixed to zero

[Add code here]

%
%   Display the world
imagesc(world);
pause(delay);
%
%   Step through all the moves
for i = 1:nstep
    %
    %   Count the number of neighbours for each site

[Add code here]

    %
    %   Update the world

[Add code here]

    %
    %   Display the world
    imagesc(world);
    pause(delay);
end

end
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

libralibra

至尊木虫 (著名写手)

骠骑将军

【答案】应助回帖

感谢参与,应助指数 +1
xzhdty: 谢谢参与 2013-11-12 10:27:22
不同生命游戏的规则可以不同,一般都是邻域小于2或者大于3,活cell会死掉.邻域等于3,死cell可以成活.如果是这个规则,5*5run5次和7*7run5次的结果如下图.自己数一下就行.

5*5run5次
求大神教MATLAB 生命游戏代码怎么写

7*7run5次
求大神教MATLAB 生命游戏代码怎么写-1
matlab/VB/python/c++/Java写程序请发QQ邮件:790404545@qq.com
3楼2013-11-11 21:15:04
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 4 个回答

chrislan625

新虫 (小有名气)

1.        Consider the following starting configuration: a world made of 5x5 squares, with 3 creatures in a horizontal line (XXX) at the centre. How many creatures are alive after 5 steps?
2.        Consider the following starting configuration: a world made of 7x7 squares, with 5 creatures in a horizontal line (XXXXX) at the centre. How many creatures are alive after 5 steps?

这是这个程序要解决的问题
2楼2013-11-11 05:42:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

chrislan625

新虫 (小有名气)

引用回帖:
3楼: Originally posted by libralibra at 2013-11-11 21:15:04
不同生命游戏的规则可以不同,一般都是邻域小于2或者大于3,活cell会死掉.邻域等于3,死cell可以成活.如果是这个规则,5*5run5次和7*7run5次的结果如下图.自己数一下就行.

5*5run5次


7*7run5次
...

大神求教~ 我们一点基础知识都没教过啊
4楼2013-11-15 09:24:29
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[公派出国] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +3 1uaZt2kAZj2S 2026-10-30 14/700 2026-11-01 07:01 by YXM1FDCSE8Bn
[考博] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +3 1uaZt2kAZj2S 2026-10-30 15/750 2026-11-01 06:53 by YXM1FDCSE8Bn
[硕博家园] 售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急 +3 X5bHxOULxFqb 2026-10-30 17/850 2026-11-01 06:48 by YXM1FDCSE8Bn
[考博] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +4 X5bHxOULxFqb 2026-10-30 21/1050 2026-11-01 06:46 by YXM1FDCSE8Bn
[考研] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +3 xvJS1BYDxvBS 2026-10-31 8/400 2026-11-01 05:48 by YXM1FDCSE8Bn
[硕博家园] 售SCI一区T0P文章,我:8.O55.1.O.54,科目全,可十急 +3 xvJS1BYDxvBS 2026-10-31 8/400 2026-11-01 05:43 by YXM1FDCSE8Bn
[找工作] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +3 1uaZt2kAZj2S 2026-10-31 6/300 2026-11-01 05:41 by YXM1FDCSE8Bn
[公派出国] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-31 6/300 2026-11-01 05:41 by YXM1FDCSE8Bn
[博后之家] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-30 15/750 2026-11-01 05:22 by YXM1FDCSE8Bn
[考研] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +3 1uaZt2kAZj2S 2026-10-31 7/350 2026-11-01 04:04 by YXM1FDCSE8Bn
[论文投稿] 售一区SCI文章T0P,我:8O.551.O54,科目全,可十急 +3 1uaZt2kAZj2S 2026-10-31 8/400 2026-11-01 03:59 by YXM1FDCSE8Bn
[找工作] 售一区SCI文章T0P,我:8O.551.O54,科目全,可十急 +3 1uaZt2kAZj2S 2026-10-31 6/300 2026-11-01 03:56 by YXM1FDCSE8Bn
[博后之家] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +3 1uaZt2kAZj2S 2026-10-31 6/300 2026-11-01 03:56 by YXM1FDCSE8Bn
[考博] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 1uaZt2kAZj2S 2026-10-31 5/250 2026-11-01 02:25 by YXM1FDCSE8Bn
[公派出国] 售一区SCI文章T0P,我:8O.551.O54,科目全,可十急 +3 1uaZt2kAZj2S 2026-10-31 4/200 2026-11-01 00:41 by YXM1FDCSE8Bn
[硕博家园] 售SCI一区T0P文章,我:8.O.55.1.O.54,科目齐全,可+急 +4 X5bHxOULxFqb 2026-10-30 12/600 2026-11-01 00:15 by YXM1FDCSE8Bn
[硕博家园] 越来越担心硕士毕业后没有竞争力了 +8 zuesli 2026-10-27 14/700 2026-10-30 22:44 by 好运连连公主
[基金申请] 论文的挂名怎么评判贡献?基金申请中,排名第一的挂名文章 +3 biily 2026-10-25 3/150 2026-10-30 18:33 by 旁观2020
[硕博家园] 申博自荐 2篇一区TOP+1篇EI+2公开发明专利 2027博士申请 +3 小小阿光 2026-10-27 3/150 2026-10-29 23:56 by 起风了的快乐
[文学芳草园] 闲聊 +3 myrtle 2026-10-25 6/300 2026-10-29 15:28 by myrtle
信息提示
请填处理意见