24小时热门版块排行榜    

查看: 1285  |  回复: 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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 08工科 320总分 求调剂 +11 梨花珞晚风 2026-03-17 11/550 2026-03-22 17:42 by luoyongfeng
[考研] 一志愿中南化学(0703)总分337求调剂 +9 niko- 2026-03-19 10/500 2026-03-22 16:08 by ColorlessPI
[考研] 311求调剂 +3 26研0 2026-03-20 3/150 2026-03-22 14:46 by ColorlessPI
[考研] 求调剂 +5 Zhangbod 2026-03-21 7/350 2026-03-22 13:13 by Zhangbod
[考研] 302求调剂 +12 呼呼呼。。。。 2026-03-17 12/600 2026-03-21 17:29 by ColorlessPI
[考研] 296求调剂 +4 www_q 2026-03-20 4/200 2026-03-21 17:26 by 学员8dgXkO
[考研] 346求调剂[0856] +4 WayneLim327 2026-03-16 7/350 2026-03-21 04:02 by JourneyLucky
[考研] 初始318分求调剂(有工作经验) +3 1911236844 2026-03-17 3/150 2026-03-21 02:33 by JourneyLucky
[考研] 南京大学化学376求调剂 +3 hisfailed 2026-03-19 6/300 2026-03-20 23:43 by hisfailed
[考研] 中南大学化学学硕337求调剂 +3 niko- 2026-03-19 6/300 2026-03-20 21:58 by luoyongfeng
[考研] A区线材料学调剂 +5 周周无极 2026-03-20 5/250 2026-03-20 21:33 by laoshidan
[考研] 求调剂 +3 eation27 2026-03-20 3/150 2026-03-20 19:32 by JourneyLucky
[考研] 材料与化工专硕调剂 +7 heming3743 2026-03-16 7/350 2026-03-20 19:31 by zhukairuo
[考研] 086500 325 求调剂 +3 领带小熊 2026-03-19 3/150 2026-03-20 18:38 by 尽舜尧1
[考研] 085410人工智能专硕317求调剂(0854都可以) +4 xbxudjdn 2026-03-18 4/200 2026-03-20 09:07 by 不168
[考研] 生物学调剂招人!!! +3 山海天岚 2026-03-17 4/200 2026-03-19 21:34 by 怎么释怀
[考研] 288求调剂,一志愿华南理工大学071005 +5 ioodiiij 2026-03-17 5/250 2026-03-19 18:22 by zcl123
[考研] 0703化学调剂 +5 pupcoco 2026-03-17 8/400 2026-03-19 13:58 by houyaoxu
[考研] 277调剂 +5 自由煎饼果子 2026-03-16 6/300 2026-03-17 19:26 by 李leezz
[考研] 一志愿苏州大学材料工程(085601)专硕有科研经历三项国奖两个实用型专利一项省级立项 +6 大火山小火山 2026-03-16 8/400 2026-03-17 15:05 by 无懈可击111
信息提示
请填处理意见