24小时热门版块排行榜    

Znn3bq.jpeg
查看: 1306  |  回复: 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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 211本科材料化工求调剂 +14 YHLAH 2026-04-11 15/750 2026-04-12 10:38 by zhouyuwinner
[考研] 347求调剂 +4 mhyqyy 2026-04-06 4/200 2026-04-12 02:27 by 秋豆菜芽
[考研] 299求调剂 +8 ZVVZ13 2026-04-08 8/400 2026-04-12 00:40 by 蓝云思雨
[考研] 277 数一104,学硕,求调剂 +21 瓶子PZ 2026-04-09 23/1150 2026-04-11 23:12 by labixiaoqiao
[教师之家] 请问地理、遥感方面,可以做哪些横向项目啊,纵向完不成考核啊 +3 锦衣卫寒战 2026-04-07 5/250 2026-04-11 20:51 by 豫椒
[考研] 271求调剂 +21 2261744733 2026-04-11 21/1050 2026-04-11 20:19 by Angchemist
[考研] 还有化工二轮调剂的学校吗 5+14 化工人999 2026-04-09 48/2400 2026-04-11 10:27 by 89436494
[考研] 机械专硕270求调剂,接受跨专业 +12 老师看看我吧aba 2026-04-09 14/700 2026-04-11 10:21 by laoshidan
[考研] 计算机类求调剂,22408-274分 +7 上岸de小虫 2026-04-09 8/400 2026-04-10 19:56 by fxue1114
[考研] 285求调剂 +9 AZMK 2026-04-07 11/550 2026-04-10 15:24 by AZMK
[考研] 生物与医药273求调剂 +18 荔题南墙 2026-04-05 19/950 2026-04-10 08:14 by kangsm
[考研] 348求调剂 +3 candyyyi 2026-04-09 3/150 2026-04-09 17:20 by 段伟艳
[考研] 085400电子信息类(川大控制工程)求调剂可跨专业 求老师联系 +3 626776879 2026-04-08 3/150 2026-04-09 16:05 by 猪会飞
[考研] 349学科化学045106求调剂,化学类都可以 +8 保好懂懂 2026-04-08 8/400 2026-04-09 14:03 by xulei3024
[考研] 化学0703-一志愿211-338分求调剂 +10 vants 2026-04-05 11/550 2026-04-08 16:02 by screening
[考研] 一志愿西南090202求调剂 +4 在线求有学上 2026-04-07 4/200 2026-04-07 19:47 by biomichael
[考研] 22408 318分求调剂 +4 勤奋的小笼包 2026-04-06 6/300 2026-04-07 15:05 by 纸鹤555
[考研] 333求调剂 +6 合乘杨习夕 2026-04-06 6/300 2026-04-07 09:44 by 猪会飞
[考研] 考研调剂 +3 Wwwwwww哇 2026-04-06 3/150 2026-04-06 20:55 by lbsjt
[考研] (调剂)一志愿报考哈尔滨工业大学0857资源与环境专业378分考生 +7 狠狠加油 2026-04-05 8/400 2026-04-06 16:52 by momo皓
信息提示
请填处理意见