Winner GUO (asdf1)

2004-11-10 09:00:00 UTC

# TLL1

Status: Passed
Results: 6571109
CPU Time: 76.9627
Score: 6573.86
Submitted at: 2004-11-03 19:29:39 UTC
Scored at: 2004-11-04 05:20:53 UTC

Current Rank: 1239th

Timothy Alderson
03 Nov 2004
Random all the way
Code
```function mv = solver_main(ai,af,w)
rand('state',1111);
nBlocks = max(ai(:));
[m,n] = size(ai);
% Make increment tables
% N=1, E=2, S=3, W=4
I = [0  1  0 -1];
J = [1  0 -1  0];
a = ai;
mv = [];
iteration=0;iteration1=0;
bid_old=0;
while 1;
% Pick a random block
bid = ceil(rand*nBlocks);
if bid_old==bid;continue;end;bid_old=bid;
[i,j] = find(a==bid);
% check to see if correct already if so dont change unless randomly want to
iteration=iteration+1;thr=5./(iteration);no_change=(af(i,j)==bid);if (no_change)&&(rand<thr);continue;end;
% Move it in a random direction
r = ceil(rand*4);
ni = i + I(r);
nj = j + J(r);
% Is it a legal move? Check edges and for collision
if ((ni<1) || (ni>m) || (nj<1) || (nj>n) || (a(ni,nj)>0));continue;end;
% Check distance
% Get the target location
if no_change;d=0;dn=1;else;
[ti,tj] = find(af==bid);
d = (ti-i)^2 + (tj-j)^2;
dn = (ti-ni)^2 + (tj-nj)^2;
end;
% Have we moved closer to the target location?
iteration1=iteration1+1;thr=(iteration1)/100;if thr>.05;thr=.05;end;
if (d<dn) && (rand>thr);continue;end;
% Move the block
a(ni,nj) = bid;
a(i,j) = 0;
% Record the move
mv(end+1,[1 2]) = [bid r];
% check if same as last
if (length(mv)>2) && (mv(end,1)==mv(end-1,1)) && (abs(mv(end,2)-mv(end-1,2))==2)
mv(end-1:end,:)=[];
end;
if isequal(af,a);return;end;
end```