sb=[
  0 0 0 9 0 4 0 6 0;
  0 0 4 0 1 0 0 0 3;
  0 0 0 0 0 6 1 0 8;
  0 0 6 0 0 5 7 8 0;
  0 8 0 0 0 0 0 1 0;
  0 4 9 8 0 0 3 0 0;
  6 0 7 1 0 0 0 0 0;
  2 0 0 0 9 0 6 0 0;
  0 3 0 5 0 7 0 0 0];

[y x]=ndgrid(1:9,1:9);

%% plot Board I
  
gr1=repmat([1-.5 9+.5]',1,4);
gr2=repmat((.5:3:9.5),2,1);

gr1s=repmat([1-.5 9+.5]',1,10);
gr2s=repmat((.5:1:9.5),2,1);


ii=find(sb>0);
simage(sb)
text(x(ii),y(ii),num2str(sb(ii)))
hold on
plot(gr1,gr2,'k',gr2,gr1,'k','linewidth',5);
plot(gr1s,gr2s,'k',gr2s,gr1s,'k','linewidth',2);
hold off;
pause;

%% create Board II

sb2=zeros(9,9,9);
ii=find(sb>0);
sb2(sub2ind(size(sb2),x(ii),y(ii),sb(ii)))=1;
ii=repmat(find(sb==0),1,9);
z=repmat((1:9),length(find(sb==0)),1);
sb2(sub2ind(size(sb2),x(ii),y(ii),z))=1;

gr1=repmat([1-.5 27+.5]',1,4);
gr2=repmat((.5:9:27.5),2,1);

gr1s=repmat([1-.5 27+.5]',1,10);
gr2s=repmat((.5:3:27.5),2,1);

gr1t=repmat([1-.5 27+.5]',1,28);
gr2t=repmat((.5:1:27.5),2,1);

%% draw board II

simage(reshape(permute(reshape(sb2,9,9,3,3),[4 2 3 1]),27,27));

hold on
plot(gr1,gr2,'k',gr2,gr1,'k','linewidth',3);
plot(gr1s,gr2s,'k',gr2s,gr1s,'k','linewidth',2);
plot(gr1t,gr2t,'k',gr2t,gr1t,'k','linewidth',1);

hold off;


