24小时热门版块排行榜    

查看: 1275  |  回复: 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的回帖

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的回帖

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的回帖

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的回帖
相关版块跳转 我要订阅楼主 chrislan625 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 295求调剂。一志愿报考郑州大学化学工艺学硕,总分295分 +4 yl1 2026-03-02 4/200 2026-03-02 14:36 by a不易
[考研] 江苏省农科院招调剂1名 +4 Qwertyuop 2026-03-01 4/200 2026-03-02 14:27 by 升格阿达
[考研] 材料学硕318求调剂 +9 February_Feb 2026-03-01 9/450 2026-03-02 13:31 by njzyff
[考研] 0805总分292,求调剂 +8 幻想之殇 2026-03-01 8/400 2026-03-02 12:51 by 无际的草原
[基金申请] 面上模板改不了页边距吧? +6 ieewxg 2026-02-25 7/350 2026-03-02 12:44 by stidwellNK
[考研] 265分求调剂不调专业和学校有行学上就 +6 礼堂丁真258 2026-02-28 9/450 2026-03-02 12:04 by 52hz~~
[考研] 材料学硕318求调剂 +14 February_Feb 2026-03-01 16/800 2026-03-02 11:17 by yuchj
[考研] 322求调剂 +3 熊境喆 2026-03-01 3/150 2026-03-02 08:44 by houyaoxu
[考研] 材料复试调剂 +4 学材料的点 2026-03-01 5/250 2026-03-02 08:26 by houyaoxu
[基金申请] 成果系统访问量大,请一小时后再尝试。---NSFC啥时候好哦,已经两天这样了 +4 NSFC2026我来了 2026-02-28 4/200 2026-03-01 22:37 by 铁门栓
[考研] 一志愿中南大学理学化学 +4 15779376950 2026-03-01 5/250 2026-03-01 19:00 by Fff-1
[考研] 291分工科求调剂 +9 science饿饿 2026-03-01 10/500 2026-03-01 18:55 by 18137688336
[考研] 328求调剂 +3 aaadim 2026-03-01 5/250 2026-03-01 17:29 by njzyff
[考研] 290求调剂 +9 材料专硕调剂; 2026-02-28 11/550 2026-03-01 17:21 by sunny81
[考研] 313求调剂 +3 水流年lc 2026-02-28 3/150 2026-03-01 16:01 by 新能源达人
[考研] 304求调剂 +6 曼殊2266 2026-02-28 7/350 2026-03-01 15:14 by wjLi2017
[考研] 材料284求调剂,一志愿郑州大学英一数二专硕 +10 想上岸的土拨鼠 2026-02-28 10/500 2026-03-01 14:12 by yc258
[考研] 311求调剂 +9 南迦720 2026-02-28 10/500 2026-03-01 10:55 by sunny81
[论文投稿] Optics letters投稿被拒求助 30+3 luckyry 2026-02-26 4/200 2026-03-01 09:06 by babero
[硕博家园] 【博士招生】太原理工大学2026化工博士 +4 N1ce_try 2026-02-24 8/400 2026-02-26 08:40 by N1ce_try
信息提示
请填处理意见