當前位置:編程學習大全網 - 源碼下載 - 炸飛機的炸飛機的Matlab源代碼(喵裏葉變換版)

炸飛機的炸飛機的Matlab源代碼(喵裏葉變換版)

functionplane%PLANEplaysthebombingplanegame.%Ata10x10airportlyingthreeplanes.Trytousetheleastbombs%toblowupallthethreeplanes.%%Theplane'sshapeisdeterminedbythematrixasfellow:%00600%55555%00500%05550%wherenumber6responsestheheadpartofeachplaneand%number5responsesthebody.Onlywhentheheadpartof%theplaneisblowedup,theplanewouldbecompletelydes-%toried.Youwinthegamewhenallthreeplanesareblowed%up.%%Duringthegame,youshallsayaposition(suchas'D4')that%youwishtoblowupandtheMatlabwilltellyoutheresultas%follow:%Miss:Yourbombmissedtheplane..%Hurt:Yourbombexplodedatthebodyofaplane.%Kill:Yourbombexplodedattheheadofaplane.%Domakefulluseoftheseimformationtodeterminethe%locationsoftheplane'sheads.%%Duringthegame,typing'current'tocheckcurrentimformation%youhaveexploredintheboard.Typing'giveup'whenyouare%wishtogiveupandcheckthecorrectanswerandtyping'exit'%toexitthegame.%%Coder:MourierTransform%Cirno'scompleteCodingWorkshop%2013-9-25(Meow>w<~)globalplaneplaneupplaneleftplanedownplanerightplaneboard;plane=[0,0,6,0,05,5,5,5,50,0,5,0,00,5,5,5,0];planeup=plane;planeleft=rot90(plane);planedown=rot90(rot90(plane));planeright=rot90(rot90(rot90(plane)));planeboard=zeros(10);explored=zeros(10);step=0;i=1;while1putplane;putplane;putplane;ifislegal(planeboard)break;elsei=i+1;planeboard=zeros(10);endenddisp('');disp('Thebombingplanegame.');disp('');disp('Typethepositionyouwishtobomb.');disp('Typecurrenttochecktheexploredposition.');disp('Typegiveuptogiveup,checktherightanswerandexitthegame.');disp('Typeexittoexitthegamedirectly.');disp('');while1ifisWin(explored)disp('Congratulations!Youwonthegame.');disp(['Bombsused:',num2str(step),'.']);disp('Yourevaluationis:');ev='AirmanBasic.';ifstep<60ev='Airman.';endifstep<56ev='AirmanFirstClass.';endifstep<52ev='SeniorAirman.';endifstep<49ev='StaffSergeant.';endifstep<46ev='TechnicalSergeant.';endifstep<43ev='FirstSergeant.';endifstep<40ev='MasterSergeant.';endifstep<37ev='SeniorMasterSergeant.';endifstep<34ev='ChiefMasterSergeant.';endifstep<31ev='CommandChiefMasterSergeant.';endifstep<28ev='ChiefMasterSergeantoftheAirForce.';endifstep<26ev='SecondLieutenant.';endifstep<24ev='FirstLieutenant.';endifstep<22ev='Captain.';endifstep<20ev='Major.';endifstep<18ev='LieutenantColonel.';endifstep<16ev='Colonel.';endifstep<14ev='BrigadierGeneral.';endifstep<12ev='MajorGeneral.';endifstep<10ev='LieutenantGeneral.';endifstep<9ev='General.';endifstep<8ev='GeneraloftheAirForce.';endifstep<7ev='Luckyman.';endifstep<4ev='ChineseHacker.'enddisp(ev);return;endin=input('Meow:','s');switchincase'current'disp('Bombsused:');disp(step);disp('Positionexploredasfellow:');disp(explored);disp('0-Hasnotbeenexplored');disp('1-Missed');disp('2-Hurt');disp('3-Killed');case'giveup'disp('Yougaveup.....nowchecktheanswer:');disp(planeboard);return;case'exit'disp('Exitthegame.');return;otherwise[x,y]=trans(in);ifx~=0&&y~=0switchplaneboard(x,y)case0disp('Missed.');explored(x,y)=1;step=step+1;case5disp('Hurttheplane.');explored(x,y)=2;step=step+1;case6disp('Killedtheplane,excellent!');explored(x,y)=3;step=step+1;otherwiseendelsedisp('Illegalcommand...');endendendfunction[x,y]=trans(s)%Positiontransform.x=0;y=0;ifdouble(s(1))>=65&&double(s(1))<=74x=double(s(1))-64;endifdouble(s(1))>=97&&double(s(1))<=106x=double(s(1))-96;endifdouble(s(2))>=49&&double(s(2))<=57y=double(s(2)-48);tryifs(2)=='1'&&s(3)=='0'y=10;endcatchendendfunctionputplaneglobalplaneupplaneleftplanedownplanerightplaneboard;%Putaplane.switchceil(rand*4)case1x=floor(rand*7);y=floor(rand*6);fori=1:4forj=1:5planeboard(x+i,y+j)=planeboard(x+i,y+j)+planeup(i,j);endendcase2x=floor(rand*7);y=floor(rand*6);fori=1:4forj=1:5planeboard(x+i,y+j)=planeboard(x+i,y+j)+planedown(i,j);endendcase3x=floor(rand*6);y=floor(rand*7);fori=1:5forj=1:4planeboard(x+i,y+j)=planeboard(x+i,y+j)+planeleft(i,j);endendcase4x=floor(rand*6);y=floor(rand*7);fori=1:5forj=1:4planeboard(x+i,y+j)=planeboard(x+i,y+j)+planeright(i,j);endendendfunctionx=islegal(board)%Checklegal.siz=size(board);x=1;form=1:siz(1)forn=1:siz(2)ifboard(m,n)>6x=0;break;endendendfunctionx=isWin(board)%Checkwinning.siz=size(board);x=0;tick=0;form=1:siz(1)forn=1:siz(2)ifboard(m,n)==3tick=tick+1;iftick==3x=1;break;endendendend

  • 上一篇:黑客vip網站源代碼
  • 下一篇:幫我算算命吧...
  • copyright 2024編程學習大全網