function maze
row=20
col=39
rand('森前state',sum(100*clock))
[cc,rr]=meshgrid(1:col,1:row)
state = reshape([1:row*col],row,col)
id = reshape([1:row*col],row,col)
ptr_left = zeros(size(id))
ptr_up = zeros(size(id))
ptr_right = zeros(size(id))
ptr_down = zeros(size(id))
ptr_left(:,2:size(id,2)) = id(:,1:size(id,2)-1)
ptr_up(2:size(id,1),:) = id(1:size(id,1)-1,:)
ptr_right(:,1:size(id,2)-1) = id(:,2:size(id,2))
ptr_down(1:size(id,1)-1,:) = id(2:size(id,1),:)
the_maze = cat(2,reshape(id,row*col,1),reshape(rr,row*col,1),reshape(cc,row*col,1),reshape(state,row*col,1),...
reshape(ptr_left,row*col,1),reshape(ptr_up,row*col,1),reshape(ptr_right,row*col,1),reshape(ptr_down,row*col,1) )
the_maze = sortrows(the_maze)
id=the_maze(:,1)
rr=the_maze(:,2)
cc=the_maze(:,3)
state=the_maze(:,4)
ptr_left=the_maze(:,5)
ptr_up=the_maze(:,6)
ptr_right=the_maze(:,7)
ptr_down=the_maze(:,8)
clear the_maze
[state, ptr_left, ptr_up, ptr_right, ptr_down]=...
make_pattern(row,col,rr, cc, state, ptr_left, ptr_up, ptr_right, ptr_down)
h=figure('KeyPressFcn',@move_spot,'color','white')
show_maze(row, col, rr, cc, ptr_left, ptr_up, ptr_right, ptr_down,h)
% 开始
cursor_pos=[1,1]
current_id=1
figure(h)
text(cursor_pos(1),cursor_pos(2),'\diamondsuit','HorizontalAlignment','Center','color','r')
set(gcf,'Units','normalized')
set(gcf,'position',[0 0 1 .91])
tic
% 记录亩春裤过程
while ~all(cursor_pos == [col,row])
waitfor(gcf,'迅简CurrentCharacter')
set(gcf,'CurrentCharacter','~') % update to another character so repeats are recognized
switch double(key(1))
case 108 % left
if ptr_left(current_id)<0 % check for legal move
current_id=-ptr_left(current_id)
text(cursor_pos(1),cursor_pos(2),'\diamondsuit','HorizontalAlignment','Center','color',[.8,.8,.8])
cursor_pos(1)=cursor_pos(1)-1
text(cursor_pos(1),cursor_pos(2),'\diamondsuit','HorizontalAlignment','Center','color','r')
end
case 114 % right
if ptr_right(current_id)<0 % check for legal move
current_id=-ptr_right(current_id)
text(cursor_pos(1),cursor_pos(2),'\diamondsuit','HorizontalAlignment','Center','color',[.8,.8,.8])
cursor_pos(1)=cursor_pos(1)+1
text(cursor_pos(1),cursor_pos(2),'\diamondsuit','HorizontalAlignment','Center','color','r')
end
case 117 % up
if ptr_up(current_id)<0 % check for legal move
current_id=-ptr_up(current_id)
text(cursor_pos(1),cursor_pos(2),'\diamondsuit','HorizontalAlignment','Center','color',[.8,.8,.8])
cursor_pos(2)=cursor_pos(2)-1
text(cursor_pos(1),cursor_pos(2),'\diamondsuit','HorizontalAlignment','Center','color','r')
end
case 100 % down
if ptr_down(current_id)<0 % check for legal move
current_id=-ptr_down(current_id)
text(cursor_pos(1),cursor_pos(2),'\diamondsuit','HorizontalAlignment','Center','color',[.8,.8,.8])
cursor_pos(2)=cursor_pos(2)+1
text(cursor_pos(1),cursor_pos(2),'\diamondsuit','HorizontalAlignment','Center','color','r')
end
otherwise
end
end
thyme=toc
title(cat(2,' Winning Time ',num2str(round(thyme*100)/100),'(sec)'),'FontSize',20)
return
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、子程序、、、、、、、、、、、、、、、、、、、、、、、、、、、、
function move_spot(src,evnt)%获取方向建
assignin('caller','key',evnt.Key)
return
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
function show_maze(row, col, rr, cc, ptr_left, ptr_up, ptr_right, ptr_down,h)
%显示迷宫
figure(h)
line([.5,col+.5],[.5,.5]) % draw top border
line([.5,col+.5],[row+.5,row+.5]) % draw bottom border
line([.5,.5],[1.5,row+.5]) % draw left border
line([col+.5,col+.5],[.5,row-.5]) % draw right border
for ii=1:length(ptr_right)
if ptr_right(ii)>0 % right passage blocked
line([cc(ii)+.5,cc(ii)+.5],[rr(ii)-.5,rr(ii)+.5])
hold on
end
if ptr_down(ii)>0 % down passage blocked
line([cc(ii)-.5,cc(ii)+.5],[rr(ii)+.5,rr(ii)+.5])
hold on
end
end
axis equal
axis([.5,col+.5,.5,row+.5])
axis off
set(gca,'YDir','reverse')
return
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
function [state, ptr_left, ptr_up, ptr_right, ptr_down]=make_pattern(row,col, rr, cc, state, ptr_left, ptr_up, ptr_right, ptr_down)%产生边界道路信息
while max(state)>1
tid=ceil(col*row*rand(15,1))
cityblock=cc(tid)+rr(tid)
is_linked=(state(tid)==1)
temp = sortrows(cat(2,tid,cityblock,is_linked),[3,2])
tid = temp(1,1)
dir=ceil(4*rand)
switch dir
case 1
if ptr_left(tid)>0 &state(tid)~=state(ptr_left(tid))
state( state==state(tid) | state==state(ptr_left(tid)) )=min([state(tid),state(ptr_left(tid))])
ptr_right(ptr_left(tid))=-ptr_right(ptr_left(tid))
ptr_left(tid)=-ptr_left(tid)
end
case 2
if ptr_right(tid)>0 &state(tid)~=state(ptr_right(tid))
state( state==state(tid) | state==state(ptr_right(tid)) )=min([state(tid),state(ptr_right(tid))])
ptr_left(ptr_right(tid))=-ptr_left(ptr_right(tid))
ptr_right(tid)=-ptr_right(tid)
end
case 3
if ptr_up(tid)>0 &state(tid)~=state(ptr_up(tid))
state( state==state(tid) | state==state(ptr_up(tid)) )=min([state(tid),state(ptr_up(tid))])
ptr_down(ptr_up(tid))=-ptr_down(ptr_up(tid))
ptr_up(tid)=-ptr_up(tid)
end
case 4
if ptr_down(tid)>0 &state(tid)~=state(ptr_down(tid))
state( state==state(tid) | state==state(ptr_down(tid)) )=min([state(tid),state(ptr_down(tid))])
ptr_up(ptr_down(tid))=-ptr_up(ptr_down(tid))
ptr_down(tid)=-ptr_down(tid)
end
otherwise
dir
error('quit')
end
end
return
num=randi(100,[1 1])
i=0
while (i<3)
elseif(a>num)
disp 'High'
i=i+1
else
end
if (i==3)
disp '扮虚You lose'
end
#include <stdio.h>
int main()
printf("enter the integer you guess:")
scanf("%d", &t)
if (data == t)
{
printf("the data is:%d\n", data)
break
}
else if(data >t)
else
count++
}while(1)
if (count <= 3)
else if(count <= 7)
return 0
编程环境
MATLAB由一系列工具组成。这些工具方便用户使用MATLAB的函数和文件,其中许多工具采用的是图形用户界面。包括MATLAB桌面和命令窗口、历史命令窗口、编辑器和调试器、路径搜索和用于用户浏览帮助、工作空间、文件的浏览器。
随着MATLAB的商业化以及软件本身的不断升级数猜,MATLAB的用户界面也越来越精致,更加接近Windows的标准界面,人机交互性更强, *** 作薯缺型更简单。而且新版本的MATLAB提供了完整的联机查询、帮助系统,极大的方便了用户的使用。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)