image thumbnail

Mathworks Rubik version 2

by

 

04 Apr 2013 (Updated )

Display, tester and solver of the Rubik's game, including "full cubes".

s=hist2string(in)
function s=hist2string(in)
%hist2string - Convert history to string
%     s=hist2string(hAxes);	% if hAxes not given, an axes is searched
%          takes the data from the axes' userdata
%     s=hist2string(Cube);
%          takes the data from the Cubes history
%     s=hist2string(history);
%          uses directly the array of the same type as the history
%
%   surfaces : F (Axe=1, Side=1), R (2,1), U (3,1),
%              B (1,-1), L (2,-1), D (3,-1)
%       are used.

Surfs='DLB FRU';
if nargin<1
	h=FindRubikAxes;
	Cube=get(h,'UserData');
	H=Cube.history;
elseif isstruct(in)
	H=in.history;
else
	H=in;
end
if isempty(H)
	s='';
	return
end
s=char(zeros(1,size(H,1)+sum(H(:,3)<0)));
iS=0;
for i=1:size(H,1)
	iS=iS+1;
	s(iS)=Surfs(H(i,1)*H(i,2)+4);
	if H(i,3)<0
		iS=iS+1;
		s(iS)='''';
	elseif i>1&s(iS)==s(iS-1)
		s(iS)='2';
	elseif H(i,3)>1
		iS=iS+1;
		s(iS)=num2str(H(i,3));
	end
end

Contact us