日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab 扫雷命令,Matlab版扫雷

發布時間:2025/3/17 循环神经网络 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab 扫雷命令,Matlab版扫雷 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我發現有些人平常閑著的時候會玩window自帶的游戲,其中最常見的就是掃雷和紙牌。本來想用matlab編寫全自動掃雷程序用來作弊,可是后來發現掃雷問題是NP完全問題(正如:旅行商NP難問題一樣不能被解決),便放棄了。于是編寫了類似掃雷游戲(沒有經過大量測試,可能有bug,效率也不高,作弊:在命令窗口輸入minefield 其中,值為1的地方為雷區)。大致規則和原來一樣,只是做了些改進:加入了音樂和語音提示。具體代碼如下(下面有兩個文件:一個腳本文件,一個函數文件,只需運行第一個文件即可):

1.腳本文件:

clear all;

row=10;

col=10;

num=30;

jieshu=0;

%global flag;

flag=zeros(row,col);

flag1=ones(row,col);

minenum=zeros(row,col);

minefield=rand(row,col);

[temp,index]=sort(minefield(:));

minefield=(minefield<=minefield(index(num)));

count=0;

for i=1:row

for j=1:col

x1=i-1;y1=j-1;

x2=i-1;y2=j;

x3=i-1;y3=j+1;

x4=i; y4=j-1;

x5=i; y5=j+1;

x6=i+1;y6=j-1;

x7=i+1;y7=j;

x8=i+1;y8=j+1;

if x1>0&&y1>0

if minefield(x1,y1)==1

count=count+1;

end

end

if x2>0

if minefield(x2,y2)==1

count=count+1;

end

end

if x3>0&&y3<11

if minefield(x3,y3)==1

count=count+1;

end

end

if y4>0

if minefield(x4,y4)==1

count=count+1;

end

end

if y5<11

if minefield(x5,y5)==1

count=count+1;

end

end

if x6<11&&y6>0

if minefield(x6,y6)==1

count=count+1;

end

end

if x7<11

if minefield(x7,y7)==1

count=count+1;

end

end

if x8<11&&y8<11

if minefield(x8,y8)==1

count=count+1;

end

end

minenum(i,j)=count;

count=0;

end

end

hf=figure(‘NumberTitle‘,‘off‘,‘Name‘,‘掃雷‘,‘menubar‘,‘none‘);

uh1=uimenu(‘label‘,‘游戲‘);

uimenu(uh1,‘label‘,‘背景顏色選擇‘,‘callback‘,‘c=uisetcolor([0 0 1],‘‘選擇顏色‘‘);set(hf,‘‘color‘‘,c);‘);

uh2=uimenu(‘label‘,‘幫助‘);

uimenu(uh2,‘label‘,‘游戲規則‘,‘callback‘,[‘text(-0.05,0,‘‘與window自帶的掃雷不同的是:雷用黑色標記,右擊時用紅色作記號,‘‘,‘‘fontsize‘‘,12,‘‘fontname‘‘,‘‘宋體‘‘);‘,...

‘hold on; text(-0.12,-0.07,‘‘輸了后,會有音樂和語音提示,贏了后,會有語音提示!‘‘,‘‘fontsize‘‘,12,‘‘fontname‘‘,‘‘宋體‘‘) ; axis off ‘]);

uimenu(uh2,‘label‘,‘制作信息‘,‘callback‘,‘msgbox(‘‘copyright:Wteng Thanks for using!‘‘)‘);

for m=1:row;

for n=1:col;

h(m,n)=uicontrol(gcf,‘style‘,‘push‘,...

‘foregroundColor‘,0.7*[1,1,1],...

‘string‘,strcat(num2str(m),num2str(n)),...

‘unit‘,‘normalized‘,‘position‘,[0.16+0.053*n,0.9-0.073*m,0.05,0.07],...

‘BackgroundColor‘,0.7*[1,1,1],‘fontsize‘,17,...

‘fontname‘,‘times new roman‘,...

‘ButtonDownFcn‘,[‘if isequal(get(gcf,‘‘SelectionType‘‘),‘‘alt‘‘)‘,...

‘ if ~get(gco,‘‘Value‘‘) if isequal(get(gco,‘‘Tag‘‘),‘‘y‘‘) ‘,...

‘set(gco,‘‘style‘‘,‘‘push‘‘,‘‘string‘‘,‘‘‘‘,‘‘backgroundcolor‘‘,0.7*[1 1 1]);‘,...

‘set(gco,‘‘Tag‘‘,‘‘n‘‘); else set(gco,‘‘style‘‘,‘‘text‘‘,‘‘string‘‘,‘‘‘‘,‘‘backgroundcolor‘‘,[1 0 0]);‘,...

‘set(gco,‘‘Tag‘‘,‘‘y‘‘);end;end;end‘],...

‘Callback‘,[‘h1=gcbo;[mf,nf]=find(h==h1);search(mf,nf,minenum,h,minefield,flag,jieshu);‘...

‘for i=1:10 for j=1:10 hcomp(i,j)=get(h(i,j),‘‘value‘‘); end;end;comp=(~hcomp==minefield);‘,...

‘if all(comp(:)) mh=msgbox(‘‘你好厲害喲!!‘‘,‘‘提示‘‘);sp=actxserver(‘‘SAPI.SpVoice‘‘);sp.Speak(‘‘你好厲害喲!‘‘); end;‘]);

end

end2.搜索蔓延函數如下:

function search(mf,nf,minenum,h,minefield,flag,jieshu)

if flag==minefield

mh=msgbox(‘你好厲害喲!‘,‘提示‘);

end

if minefield(mf,nf)==1

set(gco,‘style‘,‘text‘,‘string‘,‘‘,‘backgroundcolor‘,[0 0 0]);

load handel;

sound(y,Fs)

pause(10);

mh=msgbox(‘您輸了!請再接再厲!‘,‘提示‘);

sp=actxserver(‘SAPI.SpVoice‘);

sp.Speak(‘您輸了!請再接再厲!‘)

pause(2)

close all;

delete(hf);

else

if minenum(mf,nf)==0

flag(mf,nf)=1;

set(h(mf,nf),‘string‘,‘‘);

set(h(mf,nf),‘value‘,1);

mf1=mf-1;nf1=nf-1;

mf2=mf-1;nf2=nf;

mf3=mf-1;nf3=nf+1;

mf4=mf; nf4=nf-1;

mf5=mf; nf5=nf+1;

mf6=mf+1;nf6=nf-1;

mf7=mf+1;nf7=nf;

mf8=mf+1;nf8=nf+1;

if mf1>0&&nf1>0 && flag(mf1,nf1)==0

flag(mf1,nf1)=1;

if minenum(mf1,nf1)==0

set(h(mf1,nf1),‘style‘,‘text‘,‘string‘,‘‘,‘backgroundcolor‘,[0 0 0]);

else

set(h(mf1,nf1),‘string‘,num2str(minenum(mf1,nf1)));

set(h(mf1,nf1), ‘foregroundColor‘,0.1*[1,1,1]);

set(h(mf1,nf1),‘style‘,‘text‘,‘backgroundcolor‘,[1 1 1]);

end

if minenum(mf1,nf1)==0

search(mf1,nf1,minenum,h,minefield,flag,jieshu);

end

set(h(mf1,nf1),‘value‘,1);

end

if mf2>0 && flag(mf2,nf2)==0

flag(mf2,nf2)=1;

if minenum(mf2,nf2)==0

set(h(mf2,nf2),‘style‘,‘text‘,‘string‘,‘‘,‘backgroundcolor‘,[0 0 0]);

else

set(h(mf2,nf2),‘string‘,num2str(minenum(mf2,nf2)));

end

set(h(mf2,nf2), ‘foregroundColor‘,0.1*[1,1,1]);

set(h(mf2,nf2),‘style‘,‘text‘,‘backgroundcolor‘,[1 1 1]);

if minenum(mf2,nf2)==0

search(mf2,nf2,minenum,h,minefield,flag,jieshu);

end

set(h(mf2,nf2),‘value‘,1);

end

if mf3>0&&nf3<11 && flag(mf3,nf3)==0

flag(mf3,nf3)=1;

if minenum(mf3,nf3)==0

set(h(mf3,nf3),‘style‘,‘text‘,‘string‘,‘‘,‘backgroundcolor‘,[0 0 0]);

else

set(h(mf3,nf3),‘string‘,num2str(minenum(mf3,nf3)));

end

set(h(mf3,nf3), ‘foregroundColor‘,0.1*[1,1,1]);

set(h(mf3,nf3),‘style‘,‘text‘,‘backgroundcolor‘,[1 1 1]);

if minenum(mf3,nf3)==0

search(mf3,nf3,minenum,h,minefield,flag,jieshu);

end

set(h(mf3,nf3),‘value‘,1);

end

if nf4>0 && flag(mf4,nf4)==0

flag(mf4,nf4)=1;

if minenum(mf4,nf4)==0

set(h(mf4,nf4),‘style‘,‘text‘,‘string‘,‘‘,‘backgroundcolor‘,[0 0 0]);

else

set(h(mf4,nf4),‘string‘,num2str(minenum(mf4,nf4)));

end

set(h(mf4,nf4), ‘foregroundColor‘,0.1*[1,1,1]);

set(h(mf4,nf4),‘style‘,‘text‘,‘backgroundcolor‘,[1 1 1]);

if minenum(mf4,nf4)==0

search(mf4,nf4,minenum,h,minefield,flag,jieshu);

end

set(h(mf4,nf4),‘value‘,1);

end

if nf5<11 && flag(mf5,nf5)==0

flag(mf5,nf5)=1;

if minenum(mf5,nf5)==0

set(h(mf5,nf5),‘style‘,‘text‘,‘string‘,‘‘,‘backgroundcolor‘,[0 0 0]);

else

set(h(mf5,nf5),‘string‘,num2str(minenum(mf5,nf5)));

end

set(h(mf5,nf5), ‘foregroundColor‘,0.1*[1,1,1]);

set(h(mf5,nf5),‘style‘,‘text‘,‘backgroundcolor‘,[1 1 1]);

if minenum(mf5,nf5)==0

search(mf5,nf5,minenum,h,minefield,flag,jieshu);

end

set(h(mf5,nf5),‘value‘,1);

end

if mf6<11&&nf6>0 && flag(mf6,nf6)==0

flag(mf6,nf6)=1;

if minenum(mf6,nf6)==0

set(h(mf6,nf6),‘style‘,‘text‘,‘string‘,‘‘,‘backgroundcolor‘,[0 0 0]);

else

set(h(mf6,nf6),‘string‘,num2str(minenum(mf6,nf6)));

end

set(h(mf6,nf6), ‘foregroundColor‘,0.1*[1,1,1]);

set(h(mf6,nf6),‘style‘,‘text‘,‘backgroundcolor‘,[1 1 1]);

if minenum(mf6,nf6)==0

search(mf6,nf6,minenum,h,minefield,flag,jieshu);

end

set(h(mf6,nf6),‘value‘,1);

end

if mf7<11 && flag(mf7,nf7)==0

flag(mf7,nf7)=1;

if minenum(mf7,nf7)==0

set(h(mf7,nf7),‘style‘,‘text‘,‘string‘,‘‘,‘backgroundcolor‘,[0 0 0]);

else

set(h(mf7,nf7),‘string‘,num2str(minenum(mf7,nf7)));

end

set(h(mf7,nf7), ‘foregroundColor‘,0.1*[1,1,1]);

set(h(mf7,nf7),‘style‘,‘text‘,‘backgroundcolor‘,[1 1 1]);

if minenum(mf7,nf7)==0

search(mf7,nf7,minenum,h,minefield,flag,jieshu);

end

set(h(mf7,nf7),‘value‘,1);

end

if mf8<11&&nf8<11 && flag(mf8,nf8)==0

flag(mf8,nf8)=1;

if minenum(mf8,nf8)==0

set(h(mf8,nf8),‘style‘,‘text‘,‘string‘,‘‘,‘backgroundcolor‘,[0 0 0]);

else

set(h(mf8,nf8),‘string‘,num2str(minenum(mf8,nf8)));

end

set(h(mf8,nf8), ‘foregroundColor‘,0.1*[1,1,1]);

set(h(mf8,nf8),‘style‘,‘text‘,‘backgroundcolor‘,[1 1 1]);

if minenum(mf8,nf8)==0

search(mf8,nf8,minenum,h,minefield,flag,jieshu);

end

set(h(mf8,nf8),‘value‘,1);

end

else

set(h(mf,nf),‘string‘,num2str(minenum(mf,nf)));

end

set(h(mf,nf), ‘foregroundColor‘,0.1*[1,1,1]);

set(h(mf,nf),‘style‘,‘text‘,‘backgroundcolor‘,[1 1 1]);

end

end1.開始界面

2.輸了的界面

3.贏了的界面

原文:http://blog.csdn.net/tengweitw/article/details/20228303

新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!

總結

以上是生活随笔為你收集整理的matlab 扫雷命令,Matlab版扫雷的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。