24小时热门版块排行榜    

Znn3bq.jpeg
查看: 1304  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 070300化学279求调剂 +19 哈哈哈^_^ 2026-04-08 20/1000 2026-04-11 20:43 by stoner78
[考研] 300分求调剂 (085501机械专硕,本科扬大) +8 xu@841019 2026-04-11 8/400 2026-04-11 10:46 by qingpingzhu
[考研] 求调剂 +13 雪逢冬 2026-04-10 13/650 2026-04-11 09:58 by 猪会飞
[考研] 22408 352分求调剂0854类 +4 努力的夏末 2026-04-09 4/200 2026-04-11 09:57 by zhq0425
[考研] 311求调剂 +13 xyp想读书 2026-04-10 14/700 2026-04-11 09:41 by 猪会飞
[考研] 一志愿东北大学控制工程085406数二英二385,求调剂 +8 Ezra_Zhang 2026-04-09 8/400 2026-04-11 09:15 by 猪会飞
[考研] 人工智能320调剂08工类还有机会吗 +11 振—TZ 2026-04-10 11/550 2026-04-10 21:51 by blankyung
[考研] 0856专硕求调剂 希望是a区院校 +21 好好休息好不好 2026-04-09 24/1200 2026-04-10 16:58 by luoyongfeng
[考研] 282,电气工程专业,求调剂,不挑专业 +9 jggshjkkm 2026-04-10 9/450 2026-04-10 14:55 by 逆水乘风
[考研] 一志愿华东师范生物学326分,求调剂 +8 刘墨墨 2026-04-09 8/400 2026-04-10 12:00 by pengliang8036
[考研] 调剂申请086000一志愿西北农林科技大学生物与医药320分-本科齐鲁工业大学 +3 美美女士 2026-04-09 3/150 2026-04-10 10:31 by liuhuiying09
[考研] 一志愿中科院105500专业总分315求调剂 +6 lallalh 2026-04-09 7/350 2026-04-09 17:51 by lallalh
[考研] 一志愿武理车辆 281 求调剂 +5 上岸研究生. 2026-04-07 5/250 2026-04-09 15:56 by only周
[考研] 求调剂 +3 猪肉墩粉条cc 2026-04-08 4/200 2026-04-09 10:05 by 猪肉墩粉条cc
[考研] 材料与化工专硕306分找合适调剂 +27 沧海轻舟e 2026-04-06 28/1400 2026-04-08 22:06 by wdyheheeh
[考研] 材料专硕(0856) 339分求调剂 +16 哈哈哈鹅哈哈哈 2026-04-05 16/800 2026-04-08 16:02 by luoyongfeng
[考研] 一志愿哈工大,初试329,求环境科学与工程调剂! +11 余未辛 2026-04-06 11/550 2026-04-08 15:21 by screening
[考研] 265求调剂 +19 小木虫085600 2026-04-06 21/1050 2026-04-08 10:38 by 逆水乘风
[考研] 081200-11408-367学硕求调剂 +4 1_2_3111 2026-04-06 4/200 2026-04-07 08:13 by jp9609
[考研] 362求调剂一志愿中国石油大学 +4 我要考大 2026-04-06 6/300 2026-04-06 14:11 by 无际的草原
信息提示
请填处理意见