Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2008-12-08, 15:14   #1
未注册
游客
 
帖子: n/a
默认 求高手!!8 皇后问题

国际象棋的棋盘是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,=0;% the whole row turn to be 0
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
  回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码


相似的主题
主题 主题作者 版面 回复 最后发表
[资料]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


所有时间均为北京时间。现在的时间是 14:20


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.