Winner the cyclist (typ2)

Finish 2006-04-12 09:00:00 UTC

simple row/column swap and burst

by Jean-Francois Bergevin

Status: Failed
Results:

Comments
Jean-Francois Bergevin
05 Apr 2006
I am using the provided grade function to change the board entries.
Please login or create a profile.
Code
function moves = solver(board,nMoves)
%SOLVER Solve the Blockbuster Contest problem
%
% MOVES = SOLVER(BOARD,NMOVES) BlockBuster solver.
%
% MOVES -> [row,column,action]
% action -> 0 busts, 1 swap up, 2 swap right, 3 swap down, 4 swap left
[ver,hor] = size(board);
if ver>=hor
    orientation = 0;
else
    orientation = 1;
end
check = 0;
for cnt = 1 : nMoves

    if orientation == 0
        [zcol,zrow] = find(board' == 0);
        [a,b] = mode(board');
        a(zrow) = zeros(1,length(zrow));
        b(zrow) = zeros(1,length(zrow));
        d = find(max(a) == a,1);
        e = find(board(d,:) == max(a));
        if length(e) > (hor)/2
            e = find(board(d,:) == max(a),ceil((length(e)/2)));
        end
    else
        [zcol,zrow] = find(board == 0);
        [a,b] = mode(board);
        a(zrow) = zeros(1,length(zrow));
        b(zrow) = zeros(1,length(zrow));
        d = find(max(a) == a,1);
        e = find(board(:,d) == max(a));
        if length(e) > (ver)/2
            e = find(board(:,d) == max(a),ceil((length(e)/2)));
        end
    end
    
    if (length(find((e(1:end-1) - e(2:end)) == -1)) > (length(e)/2)) == 1
        moves(cnt,:) = [d e(1) 0];
        check = 1;
    end
    
    if check == 0
        for cnt2 = 1 : length(e)-1
            if ((e(cnt2+1) - e(cnt2)) ~= 1) & (cnt2 <= (length(e)-1)/2)
                if orientation == 0
                    moves(cnt,:) = [d e(cnt2) 2];
                else
                    moves(cnt,:) = [e(cnt2) d 3];
                end
                check = 1;
                break;
            elseif ((e(cnt2+1) - e(cnt2)) ~= 1) & (cnt2 > (length(e)-1)/2)
                if orientation == 0
                    moves(cnt,:) = [d e(cnt2+1) 4];
                else
                    moves(cnt,:) = [e(cnt2+1) d 1];
                end
                check = 1;
                break;
            end
        end
    end
    if check == 0
        moves(cnt,:) = [d e(end) 0];
    end
    check = 0;
    [score,board] = grade(board,nMoves,moves(cnt,:));
end