Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
游客
帖子: n/a
|
![]()
国际象棋的棋盘是8x8 皇后可以竖着走横着走 和走对角线 要在棋盘上摆八个皇后
想用matlab写一个国际象棋的8皇后的程序, 我已经有了一个皇后的程序,只需要写一个script file,在其中利用已有的皇后程序来完成8个皇后的摆放。在程序里先建一个ones(8,8)矩阵,然后用queen的方程来摆 我的皇后程序如下: %queen functions function [a,ch]=queen(r,c,a) % r=row % c=column % a=board % ch=check % if the board changed, ch=1 % if the board not changed, ch=0 h=a(r,c); % the position that you chose if h==1 % if the position is 1 means it's safe a(r, ![]() a(:,c)=0;% the whole column turn to be 0 a(r,c)=4;% the palce that you choos became 4 which represent queen for u=1:min(7-(8-r),7-(8-c)) a(r-u,c-u)=0; %the diagonal to the top left turn to be 0 end for u=1:min(7-(8-r),8-c) a(r-u,c+u)=0; % the diagonal to the top right turn to be 0 end for u=1:min(8-r,7-(8-c)) a(r+u,c-u)=0;% the diagonal to the left bottom turn to be 0 end for u=1:min(8-r,8-c) a(r+u,c+u)=0; ch=1; % the diagonal to the right bottom turn to be 0 end else ch=0; end |
![]() |
|
|
![]() |
||||
主题 | 主题作者 | 版面 | 回复 | 最后发表 |
[资料]MATLAB GUI 界面 毕业设计 重要参考资料 | wa2003 | MATLAB论坛 | 32 | 2012-04-06 15:34 |
[求助]怎么做频率和幅度可调的指数波? | nnsn | LabVIEW论坛 | 0 | 2009-01-05 22:11 |
求大家帮忙,怎么编程求区间啊? | qfunkt | MATLAB论坛 | 1 | 2008-12-20 13:40 |
[求助]请问谁会用matlab模拟一个泊松过程? | jarod520 | MATLAB论坛 | 0 | 2008-12-10 18:53 |
[求助]求灰度图片K值 | gkyingkyin | MATLAB论坛 | 0 | 2008-05-16 09:10 |