No BSD License  

Highlights from
Finding the Similar Entries: A Quantitative Approach based on CPU Runtime Behavior

image thumbnail

Finding the Similar Entries: A Quantitative Approach based on CPU Runtime Behavior

by

 

08 Apr 2009 (Updated )

Entry to Matlab contest Spring 2009

collaborationSover(board)
% Entry ID: 42204.  Author: JohanH

function [moves,score] = collaborationSover(board)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
    rand( 'state', 0 );line_runtime=toc; runtime_info(2, :) = runtime_info(2, :) + [0 line_runtime 1]; tic;
    rand( 57, 1 );line_runtime=toc; runtime_info(3, :) = runtime_info(3, :) + [0 line_runtime 1]; tic;
    [m,n] = size( board );line_runtime=toc; runtime_info(4, :) = runtime_info(4, :) + [0 line_runtime 1]; tic;
    pegCount = sum( board( : )>0 );line_runtime=toc; runtime_info(5, :) = runtime_info(5, :) + [0 line_runtime 1]; tic;
        rows = m + 4;line_runtime=toc; runtime_info(6, :) = runtime_info(6, :) + [0 line_runtime 1]; tic;
    rv = 5:rows;line_runtime=toc; runtime_info(7, :) = runtime_info(7, :) + [0 line_runtime 1]; tic;
    cols = n + 4;line_runtime=toc; runtime_info(8, :) = runtime_info(8, :) + [0 line_runtime 1]; tic;
    cv = 5:cols;line_runtime=toc; runtime_info(9, :) = runtime_info(9, :) + [0 line_runtime 1]; tic;
    fill = (pegCount - nnz( board<0 ))/(m*n);line_runtime=toc; runtime_info(10, :) = runtime_info(10, :) + [0 line_runtime 1]; tic;
        i = repmat( rv', [ n, 1 ] );line_runtime=toc; runtime_info(11, :) = runtime_info(11, :) + [0 line_runtime 1]; tic;
        j = reshape( repmat( cv, [ m, 1 ] ), [ m*n, 1 ] );line_runtime=toc; runtime_info(12, :) = runtime_info(12, :) + [0 line_runtime 1]; tic;
    mm = m + 8;line_runtime=toc; runtime_info(13, :) = runtime_info(13, :) + [0 line_runtime 1]; tic;
    nn = n + 8;line_runtime=toc; runtime_info(14, :) = runtime_info(14, :) + [0 line_runtime 1]; tic;
    ppBoard = zeros( mm, nn );line_runtime=toc; runtime_info(15, :) = runtime_info(15, :) + [0 line_runtime 1]; tic;
    ppBoard( : ) = -1;line_runtime=toc; runtime_info(16, :) = runtime_info(16, :) + [0 line_runtime 1]; tic;
        ppBoard( rv, cv ) = board;line_runtime=toc; runtime_info(17, :) = runtime_info(17, :) + [0 line_runtime 1]; tic;
    I = [ i; i; i; i ];line_runtime=toc; runtime_info(18, :) = runtime_info(18, :) + [0 line_runtime 1]; tic;
    J = [ j; j; j; j ];line_runtime=toc; runtime_info(19, :) = runtime_info(19, :) + [0 line_runtime 1]; tic;
    K = [ i; i; i - 2; i + 2 ];line_runtime=toc; runtime_info(20, :) = runtime_info(20, :) + [0 line_runtime 1]; tic;
    L = [ j - 2; j + 2; j; j ];line_runtime=toc; runtime_info(21, :) = runtime_info(21, :) + [0 line_runtime 1]; tic;
    K1 = [ i; i; i - 4; i + 4 ];line_runtime=toc; runtime_info(22, :) = runtime_info(22, :) + [0 line_runtime 1]; tic;
    L1 = [ j - 4; j + 4; j; j ];line_runtime=toc; runtime_info(23, :) = runtime_info(23, :) + [0 line_runtime 1]; tic;
    K2 = [ i - 2; i + 2; i - 2; i + 2 ];line_runtime=toc; runtime_info(24, :) = runtime_info(24, :) + [0 line_runtime 1]; tic;
    L2 = [ j - 2; j + 2; j + 2; j - 2 ];line_runtime=toc; runtime_info(25, :) = runtime_info(25, :) + [0 line_runtime 1]; tic;
    K3 = [ i + 2; i - 2; i - 2; i + 2 ];line_runtime=toc; runtime_info(26, :) = runtime_info(26, :) + [0 line_runtime 1]; tic;
    L3 = [ j - 2; j + 2; j - 2; j + 2 ];line_runtime=toc; runtime_info(27, :) = runtime_info(27, :) + [0 line_runtime 1]; tic;
    F = I + (J - 1)*mm;line_runtime=toc; runtime_info(28, :) = runtime_info(28, :) + [0 line_runtime 1]; tic;
    T = K + (L - 1)*mm;line_runtime=toc; runtime_info(29, :) = runtime_info(29, :) + [0 line_runtime 1]; tic;
    M = (F + T)*0.5;line_runtime=toc; runtime_info(30, :) = runtime_info(30, :) + [0 line_runtime 1]; tic;
        bogusMoves = (ppBoard( F )<0) | (ppBoard( M )<0) | (ppBoard( T )<0);line_runtime=toc; runtime_info(31, :) = runtime_info(31, :) + [0 line_runtime 1]; tic;
        I( bogusMoves ) = [  ];line_runtime=toc; runtime_info(32, :) = runtime_info(32, :) + [0 line_runtime 1]; tic;
        J( bogusMoves ) = [  ];line_runtime=toc; runtime_info(33, :) = runtime_info(33, :) + [0 line_runtime 1]; tic;
        K( bogusMoves ) = [  ];line_runtime=toc; runtime_info(34, :) = runtime_info(34, :) + [0 line_runtime 1]; tic;
        L( bogusMoves ) = [  ];line_runtime=toc; runtime_info(35, :) = runtime_info(35, :) + [0 line_runtime 1]; tic;
        F( bogusMoves ) = [  ];line_runtime=toc; runtime_info(36, :) = runtime_info(36, :) + [0 line_runtime 1]; tic;
        T( bogusMoves ) = [  ];line_runtime=toc; runtime_info(37, :) = runtime_info(37, :) + [0 line_runtime 1]; tic;
        M( bogusMoves ) = [  ];line_runtime=toc; runtime_info(38, :) = runtime_info(38, :) + [0 line_runtime 1]; tic;
        K1( bogusMoves ) = [  ];line_runtime=toc; runtime_info(39, :) = runtime_info(39, :) + [0 line_runtime 1]; tic;
        K2( bogusMoves ) = [  ];line_runtime=toc; runtime_info(40, :) = runtime_info(40, :) + [0 line_runtime 1]; tic;
        K3( bogusMoves ) = [  ];line_runtime=toc; runtime_info(41, :) = runtime_info(41, :) + [0 line_runtime 1]; tic;
        L1( bogusMoves ) = [  ];line_runtime=toc; runtime_info(42, :) = runtime_info(42, :) + [0 line_runtime 1]; tic;
        L2( bogusMoves ) = [  ];line_runtime=toc; runtime_info(43, :) = runtime_info(43, :) + [0 line_runtime 1]; tic;
        L3( bogusMoves ) = [  ];line_runtime=toc; runtime_info(44, :) = runtime_info(44, :) + [0 line_runtime 1]; tic;
        [moveid1,moveid2,moveid3] = createMoves( M, F, T );line_runtime=toc; runtime_info(45, :) = runtime_info(45, :) + [0 line_runtime 1]; tic;
    T1 = K1 + (L1 - 1)*mm;line_runtime=toc; runtime_info(46, :) = runtime_info(46, :) + [0 line_runtime 1]; tic;
    T2 = K2 + (L2 - 1)*mm;line_runtime=toc; runtime_info(47, :) = runtime_info(47, :) + [0 line_runtime 1]; tic;
    T3 = K3 + (L3 - 1)*mm;line_runtime=toc; runtime_info(48, :) = runtime_info(48, :) + [0 line_runtime 1]; tic;
    TT = [ T1, T2, T3 ];line_runtime=toc; runtime_info(49, :) = runtime_info(49, :) + [0 line_runtime 1]; tic;
    M1 = (T + T1)*0.5;line_runtime=toc; runtime_info(50, :) = runtime_info(50, :) + [0 line_runtime 1]; tic;
    M2 = (T + T2)*0.5;line_runtime=toc; runtime_info(51, :) = runtime_info(51, :) + [0 line_runtime 1]; tic;
    M3 = (T + T3)*0.5;line_runtime=toc; runtime_info(52, :) = runtime_info(52, :) + [0 line_runtime 1]; tic;
    MM = [ M1, M2, M3 ];line_runtime=toc; runtime_info(53, :) = runtime_info(53, :) + [0 line_runtime 1]; tic;
    MV = [ I, J, K, L ];line_runtime=toc; runtime_info(54, :) = runtime_info(54, :) + [0 line_runtime 1]; tic;
    MV1 = [ K, L, K1, L1 ];line_runtime=toc; runtime_info(55, :) = runtime_info(55, :) + [0 line_runtime 1]; tic;
    MV2 = [ K, L, K2, L2 ];line_runtime=toc; runtime_info(56, :) = runtime_info(56, :) + [0 line_runtime 1]; tic;
    MV3 = [ K, L, K3, L3 ];line_runtime=toc; runtime_info(57, :) = runtime_info(57, :) + [0 line_runtime 1]; tic;
    MVV = { MV1, MV2, MV3 };line_runtime=toc; runtime_info(58, :) = runtime_info(58, :) + [0 line_runtime 1]; tic;
    [moves,score] = subsoltweak( ppBoard, F, T, M, pegCount, TT, MM, MV, MVV, moveid1, moveid2, moveid3 );line_runtime=toc; runtime_info(59, :) = runtime_info(59, :) + [0 line_runtime 1]; tic;
    maxsum = sum( board( board>0 ) );line_runtime=toc; runtime_info(60, :) = runtime_info(60, :) + [0 line_runtime 1]; tic;
    maxscore = 0.81*maxsum;line_runtime=toc; runtime_info(61, :) = runtime_info(61, :) + [0 line_runtime 1]; tic;
        for dd = getDdlist( pegCount )
        if (size( moves, 1 )<=3) || (score>maxscore)
    moves = moves - 4;line_runtime=toc; runtime_info(64, :) = runtime_info(64, :) + [0 line_runtime 1]; tic;
        return
end
        [newMoves,newScore] = subsol( ppBoard, dd, 0, F, T, M, pegCount, TT, MM, MV, moveid1, moveid2, moveid3 );line_runtime=toc; runtime_info(67, :) = runtime_info(67, :) + [0 line_runtime 1]; tic;
            if (newScore>score)
                score = newScore;line_runtime=toc; runtime_info(69, :) = runtime_info(69, :) + [0 line_runtime 1]; tic;
                moves = newMoves;line_runtime=toc; runtime_info(70, :) = runtime_info(70, :) + [0 line_runtime 1]; tic;
end
end
        k = 1;line_runtime=toc; runtime_info(73, :) = runtime_info(73, :) + [0 line_runtime 1]; tic;
    while k<=(min( (pegCount*0.0078125) + 1, 3 )*(score<maxsum*0.79))
        [newMoves,newScore] = subsol( ppBoard, 1.0, 1.16, F, T, M, pegCount, TT, MM, MV, moveid1, moveid2, moveid3 );line_runtime=toc; runtime_info(75, :) = runtime_info(75, :) + [0 line_runtime 1]; tic;
            if (newScore>score)
                score = newScore;line_runtime=toc; runtime_info(77, :) = runtime_info(77, :) + [0 line_runtime 1]; tic;
                moves = newMoves;line_runtime=toc; runtime_info(78, :) = runtime_info(78, :) + [0 line_runtime 1]; tic;
end
        k = k + 1;line_runtime=toc; runtime_info(80, :) = runtime_info(80, :) + [0 line_runtime 1]; tic;
end
    moves = moves - 4;line_runtime=toc; runtime_info(82, :) = runtime_info(82, :) + [0 line_runtime 1]; tic;
    if (pegCount<272) && (fill<.96)*(score<maxsum*0.775)
        [newMoves,newScore] = solveri( board, rows, cols );line_runtime=toc; runtime_info(84, :) = runtime_info(84, :) + [0 line_runtime 1]; tic;
            if (newScore>score)
                score = newScore;line_runtime=toc; runtime_info(86, :) = runtime_info(86, :) + [0 line_runtime 1]; tic;
                moves = newMoves;line_runtime=toc; runtime_info(87, :) = runtime_info(87, :) + [0 line_runtime 1]; tic;
end
end
end
function ddlist = getDdlist(pegCount)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
        RX = 2*(rand( 4, 1 ) - 0.5);line_runtime=toc; runtime_info(92, :) = runtime_info(92, :) + [0 line_runtime 1]; tic;
    switch ceil( pegCount/102.5 )
                case 1
            ddlist = [ 1 + 0.1*RX( 1 ), 0.05 ];line_runtime=toc; runtime_info(95, :) = runtime_info(95, :) + [0 line_runtime 1]; tic;
                case 2
            ddlist = [ 6.8, 5, 2.1, 1 + 0.1*RX( 2 ), 0.6 + 0.1*RX( 2 ), 0.45 ];line_runtime=toc; runtime_info(97, :) = runtime_info(97, :) + [0 line_runtime 1]; tic;
                case 3
            ddlist = [ 0.05, 2.1, 1 + 0.1*RX( 3 ), 0.6 + 0.1*RX( 3 ), 0.4 + 0.1*RX( 3 ), 0.254 ];line_runtime=toc; runtime_info(99, :) = runtime_info(99, :) + [0 line_runtime 1]; tic;
        case 5
            ddlist = [ 0.05, 2.1, 0.6 + 0.1*RX( 4 ), 0.18 ];line_runtime=toc; runtime_info(101, :) = runtime_info(101, :) + [0 line_runtime 1]; tic;
            otherwise
            ddlist = [ 0.05, 2.1, 1 + 0.1*RX( 4 ), 0.592 ];line_runtime=toc; runtime_info(103, :) = runtime_info(103, :) + [0 line_runtime 1]; tic;
end
end
function [moveid1,moveid2,moveid3] = createMoves(M,F,T)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
    ni = max( F );line_runtime=toc; runtime_info(107, :) = runtime_info(107, :) + [0 line_runtime 1]; tic;
        nmove1 = zeros( ni, 1 );line_runtime=toc; runtime_info(108, :) = runtime_info(108, :) + [0 line_runtime 1]; tic;
    nmove2 = nmove1;line_runtime=toc; runtime_info(109, :) = runtime_info(109, :) + [0 line_runtime 1]; tic;
    nmove3 = nmove1;line_runtime=toc; runtime_info(110, :) = runtime_info(110, :) + [0 line_runtime 1]; tic;
        moveid1 = zeros( ni, 4 );line_runtime=toc; runtime_info(111, :) = runtime_info(111, :) + [0 line_runtime 1]; tic;
    moveid2 = moveid1;line_runtime=toc; runtime_info(112, :) = runtime_info(112, :) + [0 line_runtime 1]; tic;
    moveid3 = moveid1;line_runtime=toc; runtime_info(113, :) = runtime_info(113, :) + [0 line_runtime 1]; tic;
    for k = 1:numel( F )
            nmove1( F( k ) ) = nmove1( F( k ) ) + 1;line_runtime=toc; runtime_info(115, :) = runtime_info(115, :) + [0 line_runtime 1]; tic;
            moveid1( F( k ), nmove1( F( k ) ) ) = k;line_runtime=toc; runtime_info(116, :) = runtime_info(116, :) + [0 line_runtime 1]; tic;
            nmove2( M( k ) ) = nmove2( M( k ) ) + 1;line_runtime=toc; runtime_info(117, :) = runtime_info(117, :) + [0 line_runtime 1]; tic;
            moveid2( M( k ), nmove2( M( k ) ) ) = k;line_runtime=toc; runtime_info(118, :) = runtime_info(118, :) + [0 line_runtime 1]; tic;
            nmove3( T( k ) ) = nmove3( T( k ) ) + 1;line_runtime=toc; runtime_info(119, :) = runtime_info(119, :) + [0 line_runtime 1]; tic;
            moveid3( T( k ), nmove3( T( k ) ) ) = k;line_runtime=toc; runtime_info(120, :) = runtime_info(120, :) + [0 line_runtime 1]; tic;
end
end
function [moves,last_score] = solveri(board,rows,cols)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
    pBoard = zeros( rows, cols );line_runtime=toc; runtime_info(124, :) = runtime_info(124, :) + [0 line_runtime 1]; tic;
    pBoard( : ) = -1;line_runtime=toc; runtime_info(125, :) = runtime_info(125, :) + [0 line_runtime 1]; tic;
    pBoard( 3:end - 2, 3:end - 2 ) = board;line_runtime=toc; runtime_info(126, :) = runtime_info(126, :) + [0 line_runtime 1]; tic;
    nNonHoles = nnz( pBoard );line_runtime=toc; runtime_info(127, :) = runtime_info(127, :) + [0 line_runtime 1]; tic;
    moves = zeros( nNonHoles, 4 );line_runtime=toc; runtime_info(128, :) = runtime_info(128, :) + [0 line_runtime 1]; tic;
    cellbuf = zeros( nNonHoles*4, 1 );line_runtime=toc; runtime_info(129, :) = runtime_info(129, :) + [0 line_runtime 1]; tic;
        valbuf = cellbuf;line_runtime=toc; runtime_info(130, :) = runtime_info(130, :) + [0 line_runtime 1]; tic;
        movebuf = cellbuf;line_runtime=toc; runtime_info(131, :) = runtime_info(131, :) + [0 line_runtime 1]; tic;
        hopbuf = cellbuf;line_runtime=toc; runtime_info(132, :) = runtime_info(132, :) + [0 line_runtime 1]; tic;
    hop_list = cellbuf;line_runtime=toc; runtime_info(133, :) = runtime_info(133, :) + [0 line_runtime 1]; tic;
        dead_weight = 0.1*mean( board( board>0 ) );line_runtime=toc; runtime_info(134, :) = runtime_info(134, :) + [0 line_runtime 1]; tic;
    count = 0;line_runtime=toc; runtime_info(135, :) = runtime_info(135, :) + [0 line_runtime 1]; tic;
        last_move = 0;line_runtime=toc; runtime_info(136, :) = runtime_info(136, :) + [0 line_runtime 1]; tic;
    score = 0;line_runtime=toc; runtime_info(137, :) = runtime_info(137, :) + [0 line_runtime 1]; tic;
        last_pos = 0;line_runtime=toc; runtime_info(138, :) = runtime_info(138, :) + [0 line_runtime 1]; tic;
        last_score = 0;line_runtime=toc; runtime_info(139, :) = runtime_info(139, :) + [0 line_runtime 1]; tic;
        depth = 10;line_runtime=toc; runtime_info(140, :) = runtime_info(140, :) + [0 line_runtime 1]; tic;
        hop_max = 0;line_runtime=toc; runtime_info(141, :) = runtime_info(141, :) + [0 line_runtime 1]; tic;
        hop_cnt = 0;line_runtime=toc; runtime_info(142, :) = runtime_info(142, :) + [0 line_runtime 1]; tic;
    [lJumpers,lValues,lLandings] = CalculateMoves( pBoard );line_runtime=toc; runtime_info(143, :) = runtime_info(143, :) + [0 line_runtime 1]; tic;
    while true
        if isempty( lJumpers )
            break
end
        FindHops( pBoard, lJumpers, lLandings, lValues );line_runtime=toc; runtime_info(148, :) = runtime_info(148, :) + [0 line_runtime 1]; tic;
            if (hop_max~=0) && (hop_cnt>2)
                for zh = 1:hop_cnt - 1
                lJumpers = [ lJumpers; hop_list( zh ) ];line_runtime=toc; runtime_info(151, :) = runtime_info(151, :) + [0 line_runtime 1]; tic;
                lLandings = [ lLandings; hop_list( zh + 1 ) ];line_runtime=toc; runtime_info(152, :) = runtime_info(152, :) + [0 line_runtime 1]; tic;
                lValues = [ lValues; hop_max ];line_runtime=toc; runtime_info(153, :) = runtime_info(153, :) + [0 line_runtime 1]; tic;
                DoMove( numel( lJumpers ) );line_runtime=toc; runtime_info(154, :) = runtime_info(154, :) + [0 line_runtime 1]; tic;
end
    else
            [hop_values,pos] = sort( lValues, 'descend' );line_runtime=toc; runtime_info(157, :) = runtime_info(157, :) + [0 line_runtime 1]; tic;
            lValues = hop_values;line_runtime=toc; runtime_info(158, :) = runtime_info(158, :) + [0 line_runtime 1]; tic;
            lJumpers = lJumpers( pos );line_runtime=toc; runtime_info(159, :) = runtime_info(159, :) + [0 line_runtime 1]; tic;
            lLandings = lLandings( pos );line_runtime=toc; runtime_info(160, :) = runtime_info(160, :) + [0 line_runtime 1]; tic;
            for zh = 1:min( depth, numel( lJumpers ) )
                [newB,newC,newM,newV] = ProcessMove( pBoard, zh, lJumpers, lLandings, lValues );line_runtime=toc; runtime_info(162, :) = runtime_info(162, :) + [0 line_runtime 1]; tic;
                    FindHops( newB, newC, newM, newV );line_runtime=toc; runtime_info(163, :) = runtime_info(163, :) + [0 line_runtime 1]; tic;
                    hop_values( zh ) = hop_values( zh ) + hop_max;line_runtime=toc; runtime_info(164, :) = runtime_info(164, :) + [0 line_runtime 1]; tic;
end
            [max_val,pos] = max( hop_values );line_runtime=toc; runtime_info(166, :) = runtime_info(166, :) + [0 line_runtime 1]; tic;
            DoMove( pos )
end
end
    moves( last_pos + 1:end, : ) = [  ];line_runtime=toc; runtime_info(170, :) = runtime_info(170, :) + [0 line_runtime 1]; tic;
        function DoMove(pos)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
        max_cell = lJumpers( pos );line_runtime=toc; runtime_info(172, :) = runtime_info(172, :) + [0 line_runtime 1]; tic;
        max_move = lLandings( pos );line_runtime=toc; runtime_info(173, :) = runtime_info(173, :) + [0 line_runtime 1]; tic;
        count = count + 1;line_runtime=toc; runtime_info(174, :) = runtime_info(174, :) + [0 line_runtime 1]; tic;
            moves( count, : ) = [ mod( max_cell - 2, rows ), ceil( max_cell/rows ) - 2, mod( max_move - 2, rows ), ceil( max_move/rows ) - 2 ];line_runtime=toc; runtime_info(175, :) = runtime_info(175, :) + [0 line_runtime 1]; tic;
            brem = (max_cell + max_move)*0.5;line_runtime=toc; runtime_info(176, :) = runtime_info(176, :) + [0 line_runtime 1]; tic;
        score = score + pBoard( brem );line_runtime=toc; runtime_info(177, :) = runtime_info(177, :) + [0 line_runtime 1]; tic;
            if (max_cell~=last_move)
            score = score - pBoard( max_cell );line_runtime=toc; runtime_info(179, :) = runtime_info(179, :) + [0 line_runtime 1]; tic;
end
            if (score>last_score)
                last_pos = count;line_runtime=toc; runtime_info(182, :) = runtime_info(182, :) + [0 line_runtime 1]; tic;
                last_score = score;line_runtime=toc; runtime_info(183, :) = runtime_info(183, :) + [0 line_runtime 1]; tic;
end
        [pBoard,lJumpers,lLandings,lValues] = ProcessMove( pBoard, pos, lJumpers, lLandings, lValues );line_runtime=toc; runtime_info(185, :) = runtime_info(185, :) + [0 line_runtime 1]; tic;
            last_move = max_move;line_runtime=toc; runtime_info(186, :) = runtime_info(186, :) + [0 line_runtime 1]; tic;
end
    function FindHops(pBoard,lJumpers,lLandings,lValues)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
        hop_max = 0;line_runtime=toc; runtime_info(189, :) = runtime_info(189, :) + [0 line_runtime 1]; tic;
        if ~isempty( lJumpers )
            dst = lLandings( 1:numel( lJumpers ) );line_runtime=toc; runtime_info(191, :) = runtime_info(191, :) + [0 line_runtime 1]; tic;
            tmp = (~pBoard( dst + 2 ) & pBoard( dst + 1 ));line_runtime=toc; runtime_info(192, :) = runtime_info(192, :) + [0 line_runtime 1]; tic;
            tmp = (~pBoard( dst - 2 ) & pBoard( dst - 1 )) | tmp;line_runtime=toc; runtime_info(193, :) = runtime_info(193, :) + [0 line_runtime 1]; tic;
            tmp = (~pBoard( dst - 2*rows ) & pBoard( dst - rows )) | tmp;line_runtime=toc; runtime_info(194, :) = runtime_info(194, :) + [0 line_runtime 1]; tic;
            tmp = (~pBoard( dst + 2*rows ) & pBoard( dst + rows )) | tmp;line_runtime=toc; runtime_info(195, :) = runtime_info(195, :) + [0 line_runtime 1]; tic;
            idx = find( ~tmp );line_runtime=toc; runtime_info(196, :) = runtime_info(196, :) + [0 line_runtime 1]; tic;
            if ~isempty( idx )
                tmp2 = lValues( idx );line_runtime=toc; runtime_info(198, :) = runtime_info(198, :) + [0 line_runtime 1]; tic;
                [hop_max,tmp2] = max( tmp2 );line_runtime=toc; runtime_info(199, :) = runtime_info(199, :) + [0 line_runtime 1]; tic;
                tmp2 = idx( tmp2 );line_runtime=toc; runtime_info(200, :) = runtime_info(200, :) + [0 line_runtime 1]; tic;
                        hop_cnt = 2;line_runtime=toc; runtime_info(201, :) = runtime_info(201, :) + [0 line_runtime 1]; tic;
                hop_list( 1 ) = lJumpers( tmp2 );line_runtime=toc; runtime_info(202, :) = runtime_info(202, :) + [0 line_runtime 1]; tic;
                hop_list( 2 ) = lLandings( tmp2 );line_runtime=toc; runtime_info(203, :) = runtime_info(203, :) + [0 line_runtime 1]; tic;
end
            idx = find( tmp )';line_runtime=toc; runtime_info(205, :) = runtime_info(205, :) + [0 line_runtime 1]; tic;
            for ii = idx
                hopbuf( 1 ) = lJumpers( ii );line_runtime=toc; runtime_info(207, :) = runtime_info(207, :) + [0 line_runtime 1]; tic;
                FindHopTree( pBoard, lJumpers( ii ), lLandings( ii ), lValues( ii ), 2 );line_runtime=toc; runtime_info(208, :) = runtime_info(208, :) + [0 line_runtime 1]; tic;
end
end
end
    function FindHopTree(pBoard,src,dst,hop_value,count)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
        pBoard( dst ) = pBoard( src );line_runtime=toc; runtime_info(213, :) = runtime_info(213, :) + [0 line_runtime 1]; tic;
        pBoard( (src + dst)*0.5 ) = 0;line_runtime=toc; runtime_info(214, :) = runtime_info(214, :) + [0 line_runtime 1]; tic;
        pBoard( src ) = 0;line_runtime=toc; runtime_info(215, :) = runtime_info(215, :) + [0 line_runtime 1]; tic;
        hopbuf( count ) = dst;line_runtime=toc; runtime_info(216, :) = runtime_info(216, :) + [0 line_runtime 1]; tic;
        if ~pBoard( dst + 2 ) && pBoard( dst + 1 )>0
            FindHopTree( pBoard, dst, dst + 2, hop_value + pBoard( dst + 1 ), count + 1 );line_runtime=toc; runtime_info(218, :) = runtime_info(218, :) + [0 line_runtime 1]; tic;
end
        if ~pBoard( dst - 2 ) && pBoard( dst - 1 )>0
            FindHopTree( pBoard, dst, dst - 2, hop_value + pBoard( dst - 1 ), count + 1 );line_runtime=toc; runtime_info(221, :) = runtime_info(221, :) + [0 line_runtime 1]; tic;
end
        if ~pBoard( dst + 2*rows ) && pBoard( dst + rows )>0
            FindHopTree( pBoard, dst, dst + 2*rows, hop_value + pBoard( dst + rows ), count + 1 );line_runtime=toc; runtime_info(224, :) = runtime_info(224, :) + [0 line_runtime 1]; tic;
end
        if ~pBoard( dst - 2*rows ) && pBoard( dst - rows )>0
            FindHopTree( pBoard, dst, dst - 2*rows, hop_value + pBoard( dst - rows ), count + 1 );line_runtime=toc; runtime_info(227, :) = runtime_info(227, :) + [0 line_runtime 1]; tic;
end
                if hop_value>hop_max
                    hop_max = hop_value;line_runtime=toc; runtime_info(230, :) = runtime_info(230, :) + [0 line_runtime 1]; tic;
            hop_cnt = count;line_runtime=toc; runtime_info(231, :) = runtime_info(231, :) + [0 line_runtime 1]; tic;
            hop_list( 1:count ) = hopbuf( 1:count );line_runtime=toc; runtime_info(232, :) = runtime_info(232, :) + [0 line_runtime 1]; tic;
end
end
    function n = CalculateBall(pBoard,src,dst,n)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
        POP = pBoard( (src + dst)*0.5 );line_runtime=toc; runtime_info(236, :) = runtime_info(236, :) + [0 line_runtime 1]; tic;
        if POP>0 && ~pBoard( dst ) && pBoard( src )>0
                            n = n + 1;line_runtime=toc; runtime_info(238, :) = runtime_info(238, :) + [0 line_runtime 1]; tic;
            if sum( pBoard( [ dst + 1, dst - 1, dst + rows, dst - rows ] )>0 )==1
                valbuf( n ) = POP - pBoard( src ) - dead_weight;line_runtime=toc; runtime_info(240, :) = runtime_info(240, :) + [0 line_runtime 1]; tic;
    else
                valbuf( n ) = POP - pBoard( src );line_runtime=toc; runtime_info(242, :) = runtime_info(242, :) + [0 line_runtime 1]; tic;
end
                            cellbuf( n ) = src;line_runtime=toc; runtime_info(244, :) = runtime_info(244, :) + [0 line_runtime 1]; tic;
                            movebuf( n ) = dst;line_runtime=toc; runtime_info(245, :) = runtime_info(245, :) + [0 line_runtime 1]; tic;
end
end
    function n = CalculateHole(pBoard,dst,src,n)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
            pop = (src + dst)*0.5;line_runtime=toc; runtime_info(249, :) = runtime_info(249, :) + [0 line_runtime 1]; tic;
        if pBoard( pop )>0 && pBoard( src )>0
                            n = n + 1;line_runtime=toc; runtime_info(251, :) = runtime_info(251, :) + [0 line_runtime 1]; tic;
            if sum( pBoard( [ dst + 1, dst - 1, dst + rows, dst - rows ] )>0 )==1
                valbuf( n ) = pBoard( pop ) - pBoard( src ) - dead_weight;line_runtime=toc; runtime_info(253, :) = runtime_info(253, :) + [0 line_runtime 1]; tic;
    else
                valbuf( n ) = pBoard( pop ) - pBoard( src );line_runtime=toc; runtime_info(255, :) = runtime_info(255, :) + [0 line_runtime 1]; tic;
end
                            cellbuf( n ) = src;line_runtime=toc; runtime_info(257, :) = runtime_info(257, :) + [0 line_runtime 1]; tic;
                            movebuf( n ) = dst;line_runtime=toc; runtime_info(258, :) = runtime_info(258, :) + [0 line_runtime 1]; tic;
end
end
    function [new_cell_list,new_value_list,new_move_list] = CalculateMoves(pBoard)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
        zb = find( pBoard>0 );line_runtime=toc; runtime_info(262, :) = runtime_info(262, :) + [0 line_runtime 1]; tic;
        zz = find( ~pBoard );line_runtime=toc; runtime_info(263, :) = runtime_info(263, :) + [0 line_runtime 1]; tic;
            n = 0;line_runtime=toc; runtime_info(264, :) = runtime_info(264, :) + [0 line_runtime 1]; tic;
            if numel( zz )<numel( zb )
                for zi = 1:numel( zz )
                    i = zz( zi );line_runtime=toc; runtime_info(267, :) = runtime_info(267, :) + [0 line_runtime 1]; tic;
                n = CalculateHole( pBoard, i, i - 2, n );line_runtime=toc; runtime_info(268, :) = runtime_info(268, :) + [0 line_runtime 1]; tic;
                n = CalculateHole( pBoard, i, i + 2, n );line_runtime=toc; runtime_info(269, :) = runtime_info(269, :) + [0 line_runtime 1]; tic;
                n = CalculateHole( pBoard, i, i - rows*2, n );line_runtime=toc; runtime_info(270, :) = runtime_info(270, :) + [0 line_runtime 1]; tic;
                n = CalculateHole( pBoard, i, i + rows*2, n );line_runtime=toc; runtime_info(271, :) = runtime_info(271, :) + [0 line_runtime 1]; tic;
end
    else
                for zi = 1:numel( zb )
                    i = zb( zi );line_runtime=toc; runtime_info(275, :) = runtime_info(275, :) + [0 line_runtime 1]; tic;
                n = CalculateBall( pBoard, i, i - 2, n );line_runtime=toc; runtime_info(276, :) = runtime_info(276, :) + [0 line_runtime 1]; tic;
                n = CalculateBall( pBoard, i, i + 2, n );line_runtime=toc; runtime_info(277, :) = runtime_info(277, :) + [0 line_runtime 1]; tic;
                n = CalculateBall( pBoard, i, i - rows*2, n );line_runtime=toc; runtime_info(278, :) = runtime_info(278, :) + [0 line_runtime 1]; tic;
                n = CalculateBall( pBoard, i, i + rows*2, n );line_runtime=toc; runtime_info(279, :) = runtime_info(279, :) + [0 line_runtime 1]; tic;
end
end
            new_cell_list = cellbuf( 1:n );line_runtime=toc; runtime_info(282, :) = runtime_info(282, :) + [0 line_runtime 1]; tic;
            new_value_list = valbuf( 1:n );line_runtime=toc; runtime_info(283, :) = runtime_info(283, :) + [0 line_runtime 1]; tic;
            new_move_list = movebuf( 1:n );line_runtime=toc; runtime_info(284, :) = runtime_info(284, :) + [0 line_runtime 1]; tic;
end
    function [pBoard,lJumpers,lLandings,lValues] = ProcessMove(pBoard,pos,lJumpers,lLandings,lValues)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
        src = lJumpers( pos );line_runtime=toc; runtime_info(287, :) = runtime_info(287, :) + [0 line_runtime 1]; tic;
        dst = lLandings( pos );line_runtime=toc; runtime_info(288, :) = runtime_info(288, :) + [0 line_runtime 1]; tic;
            pop = (src + dst)*0.5;line_runtime=toc; runtime_info(289, :) = runtime_info(289, :) + [0 line_runtime 1]; tic;
        pBoard( dst ) = pBoard( src );line_runtime=toc; runtime_info(290, :) = runtime_info(290, :) + [0 line_runtime 1]; tic;
        pBoard( pop ) = 0;line_runtime=toc; runtime_info(291, :) = runtime_info(291, :) + [0 line_runtime 1]; tic;
        pBoard( src ) = 0;line_runtime=toc; runtime_info(292, :) = runtime_info(292, :) + [0 line_runtime 1]; tic;
            u = src - pop;line_runtime=toc; runtime_info(293, :) = runtime_info(293, :) + [0 line_runtime 1]; tic;
            if (abs( u )==1)
                v = rows;line_runtime=toc; runtime_info(295, :) = runtime_info(295, :) + [0 line_runtime 1]; tic;
    else
            v = 1;line_runtime=toc; runtime_info(297, :) = runtime_info(297, :) + [0 line_runtime 1]; tic;
end
        lLandings( logical( lLandings==dst ) ) = 0;line_runtime=toc; runtime_info(299, :) = runtime_info(299, :) + [0 line_runtime 1]; tic;
        lLandings( logical( lJumpers==src ) ) = 0;line_runtime=toc; runtime_info(300, :) = runtime_info(300, :) + [0 line_runtime 1]; tic;
        lLandings( logical( lJumpers==pop ) ) = 0;line_runtime=toc; runtime_info(301, :) = runtime_info(301, :) + [0 line_runtime 1]; tic;
        rem_src = find( lJumpers==src - v );line_runtime=toc; runtime_info(302, :) = runtime_info(302, :) + [0 line_runtime 1]; tic;
        lLandings( rem_src( lLandings( rem_src )==src + v ) ) = 0;line_runtime=toc; runtime_info(303, :) = runtime_info(303, :) + [0 line_runtime 1]; tic;
        rem_src = find( lJumpers==src + v );line_runtime=toc; runtime_info(304, :) = runtime_info(304, :) + [0 line_runtime 1]; tic;
        lLandings( rem_src( lLandings( rem_src )==src - v ) ) = 0;line_runtime=toc; runtime_info(305, :) = runtime_info(305, :) + [0 line_runtime 1]; tic;
        rem_src = find( lJumpers==src - v - u );line_runtime=toc; runtime_info(306, :) = runtime_info(306, :) + [0 line_runtime 1]; tic;
        lLandings( rem_src( lLandings( rem_src )==src + v - u ) ) = 0;line_runtime=toc; runtime_info(307, :) = runtime_info(307, :) + [0 line_runtime 1]; tic;
        rem_src = find( lJumpers==src + v - u );line_runtime=toc; runtime_info(308, :) = runtime_info(308, :) + [0 line_runtime 1]; tic;
        lLandings( rem_src( lLandings( rem_src )==src - v - u ) ) = 0;line_runtime=toc; runtime_info(309, :) = runtime_info(309, :) + [0 line_runtime 1]; tic;
        [lLandings,rem_dst] = sort( lLandings, 'descend' );line_runtime=toc; runtime_info(310, :) = runtime_info(310, :) + [0 line_runtime 1]; tic;
        lJumpers = lJumpers( rem_dst );line_runtime=toc; runtime_info(311, :) = runtime_info(311, :) + [0 line_runtime 1]; tic;
        lValues = lValues( rem_dst );line_runtime=toc; runtime_info(312, :) = runtime_info(312, :) + [0 line_runtime 1]; tic;
        ncnt = find( ~lLandings, 1, 'first' );line_runtime=toc; runtime_info(313, :) = runtime_info(313, :) + [0 line_runtime 1]; tic;
        lJumpers = lJumpers( 1:ncnt - 1 );line_runtime=toc; runtime_info(314, :) = runtime_info(314, :) + [0 line_runtime 1]; tic;
        lValues = lValues( 1:ncnt - 1 );line_runtime=toc; runtime_info(315, :) = runtime_info(315, :) + [0 line_runtime 1]; tic;
        lLandings = lLandings( 1:ncnt - 1 );line_runtime=toc; runtime_info(316, :) = runtime_info(316, :) + [0 line_runtime 1]; tic;
            n = 0;line_runtime=toc; runtime_info(317, :) = runtime_info(317, :) + [0 line_runtime 1]; tic;
        n = CalculateBall( pBoard, src - 3*u, src - u, n );line_runtime=toc; runtime_info(318, :) = runtime_info(318, :) + [0 line_runtime 1]; tic;
        n = CalculateBall( pBoard, src + 2*v - u, src - u, n );line_runtime=toc; runtime_info(319, :) = runtime_info(319, :) + [0 line_runtime 1]; tic;
        n = CalculateBall( pBoard, src + 2*v, src, n );line_runtime=toc; runtime_info(320, :) = runtime_info(320, :) + [0 line_runtime 1]; tic;
        n = CalculateBall( pBoard, src + 2*u, src, n );line_runtime=toc; runtime_info(321, :) = runtime_info(321, :) + [0 line_runtime 1]; tic;
        n = CalculateBall( pBoard, src - 2*v, src, n );line_runtime=toc; runtime_info(322, :) = runtime_info(322, :) + [0 line_runtime 1]; tic;
        n = CalculateBall( pBoard, src - 2*v - u, src - u, n );line_runtime=toc; runtime_info(323, :) = runtime_info(323, :) + [0 line_runtime 1]; tic;
        n = CalculateBall( pBoard, dst, dst - 2*u, n );line_runtime=toc; runtime_info(324, :) = runtime_info(324, :) + [0 line_runtime 1]; tic;
        n = CalculateBall( pBoard, dst, dst - 2*v, n );line_runtime=toc; runtime_info(325, :) = runtime_info(325, :) + [0 line_runtime 1]; tic;
        n = CalculateBall( pBoard, dst, dst + 2*v, n );line_runtime=toc; runtime_info(326, :) = runtime_info(326, :) + [0 line_runtime 1]; tic;
            clf = src - v - 2*u;line_runtime=toc; runtime_info(327, :) = runtime_info(327, :) + [0 line_runtime 1]; tic;
            crt = src + v - 2*u;line_runtime=toc; runtime_info(328, :) = runtime_info(328, :) + [0 line_runtime 1]; tic;
        if ~pBoard( clf )
            n = CalculateBall( pBoard, crt, clf, n );line_runtime=toc; runtime_info(330, :) = runtime_info(330, :) + [0 line_runtime 1]; tic;
end
        if ~pBoard( crt )
            n = CalculateBall( pBoard, clf, crt, n );line_runtime=toc; runtime_info(333, :) = runtime_info(333, :) + [0 line_runtime 1]; tic;
end
            if (n>0)
                if (ncnt>1)
                lJumpers = [ lJumpers; cellbuf( 1:n ) ];line_runtime=toc; runtime_info(337, :) = runtime_info(337, :) + [0 line_runtime 1]; tic;
                lLandings = [ lLandings; movebuf( 1:n ) ];line_runtime=toc; runtime_info(338, :) = runtime_info(338, :) + [0 line_runtime 1]; tic;
                lValues = [ lValues; valbuf( 1:n ) ];line_runtime=toc; runtime_info(339, :) = runtime_info(339, :) + [0 line_runtime 1]; tic;
    else
                lJumpers = cellbuf( 1:n );line_runtime=toc; runtime_info(341, :) = runtime_info(341, :) + [0 line_runtime 1]; tic;
                lValues = valbuf( 1:n );line_runtime=toc; runtime_info(342, :) = runtime_info(342, :) + [0 line_runtime 1]; tic;
                lLandings = movebuf( 1:n );line_runtime=toc; runtime_info(343, :) = runtime_info(343, :) + [0 line_runtime 1]; tic;
end
end
end
end
function [moves,v] = subsol(board,d,rfac,F,T,M,pegCount,TT,MM,MV,moveid1,moveid2,moveid3)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
        rrr = rfac*rand( 5000, 1 );line_runtime=toc; runtime_info(349, :) = runtime_info(349, :) + [0 line_runtime 1]; tic;
    moves = zeros( pegCount - 1, 4 );line_runtime=toc; runtime_info(350, :) = runtime_info(350, :) + [0 line_runtime 1]; tic;
    v0 = zeros( pegCount - 1, 1 );line_runtime=toc; runtime_info(351, :) = runtime_info(351, :) + [0 line_runtime 1]; tic;
        Bzero = ~board;line_runtime=toc; runtime_info(352, :) = runtime_info(352, :) + [0 line_runtime 1]; tic;
        Bpos = board>0;line_runtime=toc; runtime_info(353, :) = runtime_info(353, :) + [0 line_runtime 1]; tic;
        Bmax = max( board, 0 );line_runtime=toc; runtime_info(354, :) = runtime_info(354, :) + [0 line_runtime 1]; tic;
    validMoves = (Bpos( F ) & Bzero( T ) & Bpos( M ));line_runtime=toc; runtime_info(355, :) = runtime_info(355, :) + [0 line_runtime 1]; tic;
    h = find( validMoves );line_runtime=toc; runtime_info(356, :) = runtime_info(356, :) + [0 line_runtime 1]; tic;
                C0 = board( M( h ) ) - board( F( h ) );line_runtime=toc; runtime_info(357, :) = runtime_info(357, :) + [0 line_runtime 1]; tic;
            if d
                CV = max( Bmax( MM( h, : ) ) .* Bzero( TT( h, : ) ), [  ], 2 );line_runtime=toc; runtime_info(359, :) = runtime_info(359, :) + [0 line_runtime 1]; tic;
    else
                CV = 0;line_runtime=toc; runtime_info(361, :) = runtime_info(361, :) + [0 line_runtime 1]; tic;
end
                [v,k] = max( (1 + rrr( 1:length( C0 ) )) .* (C0 + CV*d) );line_runtime=toc; runtime_info(363, :) = runtime_info(363, :) + [0 line_runtime 1]; tic;
    v0( 1 ) = C0( k );line_runtime=toc; runtime_info(364, :) = runtime_info(364, :) + [0 line_runtime 1]; tic;
                k = h( k );line_runtime=toc; runtime_info(365, :) = runtime_info(365, :) + [0 line_runtime 1]; tic;
    moves( 1, : ) = MV( k, : );line_runtime=toc; runtime_info(366, :) = runtime_info(366, :) + [0 line_runtime 1]; tic;
        T0 = T( k );line_runtime=toc; runtime_info(367, :) = runtime_info(367, :) + [0 line_runtime 1]; tic;
            F0 = F( k );line_runtime=toc; runtime_info(368, :) = runtime_info(368, :) + [0 line_runtime 1]; tic;
            M0 = M( k );line_runtime=toc; runtime_info(369, :) = runtime_info(369, :) + [0 line_runtime 1]; tic;
    t = 2;line_runtime=toc; runtime_info(370, :) = runtime_info(370, :) + [0 line_runtime 1]; tic;
            Bmax( T0 ) = board( F0 );line_runtime=toc; runtime_info(371, :) = runtime_info(371, :) + [0 line_runtime 1]; tic;
            Bmax( F0 ) = 0;line_runtime=toc; runtime_info(372, :) = runtime_info(372, :) + [0 line_runtime 1]; tic;
            Bmax( M0 ) = 0;line_runtime=toc; runtime_info(373, :) = runtime_info(373, :) + [0 line_runtime 1]; tic;
            board( T0 ) = board( F0 );line_runtime=toc; runtime_info(374, :) = runtime_info(374, :) + [0 line_runtime 1]; tic;
            Bzero( T0 ) = false;line_runtime=toc; runtime_info(375, :) = runtime_info(375, :) + [0 line_runtime 1]; tic;
            Bpos( T0 ) = true;line_runtime=toc; runtime_info(376, :) = runtime_info(376, :) + [0 line_runtime 1]; tic;
            board( F0 ) = 0;line_runtime=toc; runtime_info(377, :) = runtime_info(377, :) + [0 line_runtime 1]; tic;
            Bzero( F0 ) = true;line_runtime=toc; runtime_info(378, :) = runtime_info(378, :) + [0 line_runtime 1]; tic;
            Bpos( F0 ) = false;line_runtime=toc; runtime_info(379, :) = runtime_info(379, :) + [0 line_runtime 1]; tic;
            board( M0 ) = 0;line_runtime=toc; runtime_info(380, :) = runtime_info(380, :) + [0 line_runtime 1]; tic;
            Bpos( M0 ) = false;line_runtime=toc; runtime_info(381, :) = runtime_info(381, :) + [0 line_runtime 1]; tic;
            Bzero( M0 ) = true;line_runtime=toc; runtime_info(382, :) = runtime_info(382, :) + [0 line_runtime 1]; tic;
        FF = [ F0, M0, T0 ];line_runtime=toc; runtime_info(383, :) = runtime_info(383, :) + [0 line_runtime 1]; tic;
        originatingMoves = moveid1( FF, : );line_runtime=toc; runtime_info(384, :) = runtime_info(384, :) + [0 line_runtime 1]; tic;
        originatingMoves = originatingMoves( originatingMoves>0 );line_runtime=toc; runtime_info(385, :) = runtime_info(385, :) + [0 line_runtime 1]; tic;
        jumpedMoves = moveid2( FF, : );line_runtime=toc; runtime_info(386, :) = runtime_info(386, :) + [0 line_runtime 1]; tic;
        jumpedMoves = jumpedMoves( jumpedMoves>0 );line_runtime=toc; runtime_info(387, :) = runtime_info(387, :) + [0 line_runtime 1]; tic;
        terminatingMoves = moveid3( FF, : );line_runtime=toc; runtime_info(388, :) = runtime_info(388, :) + [0 line_runtime 1]; tic;
        terminatingMoves = terminatingMoves( terminatingMoves>0 );line_runtime=toc; runtime_info(389, :) = runtime_info(389, :) + [0 line_runtime 1]; tic;
        allMoves = [ originatingMoves; jumpedMoves; terminatingMoves ];line_runtime=toc; runtime_info(390, :) = runtime_info(390, :) + [0 line_runtime 1]; tic;
        validMoves( allMoves ) = Bpos( F( allMoves ) ) & Bzero( T( allMoves ) ) & Bpos( M( allMoves ) );line_runtime=toc; runtime_info(391, :) = runtime_info(391, :) + [0 line_runtime 1]; tic;
    h = find( validMoves );line_runtime=toc; runtime_info(392, :) = runtime_info(392, :) + [0 line_runtime 1]; tic;
    while ~isempty( h )
        if (numel( h )>1)
                c = find( F( h )==T0 );line_runtime=toc; runtime_info(395, :) = runtime_info(395, :) + [0 line_runtime 1]; tic;
            if ~isempty( c )
                h = h( c );line_runtime=toc; runtime_info(397, :) = runtime_info(397, :) + [0 line_runtime 1]; tic;
                C0 = board( M( h ) );line_runtime=toc; runtime_info(398, :) = runtime_info(398, :) + [0 line_runtime 1]; tic;
    else
                C0 = board( M( h ) ) - board( F( h ) );line_runtime=toc; runtime_info(400, :) = runtime_info(400, :) + [0 line_runtime 1]; tic;
end
            if d
                CV = max( Bmax( MM( h, : ) ) .* Bzero( TT( h, : ) ), [  ], 2 );line_runtime=toc; runtime_info(403, :) = runtime_info(403, :) + [0 line_runtime 1]; tic;
    else
                CV = 0;line_runtime=toc; runtime_info(405, :) = runtime_info(405, :) + [0 line_runtime 1]; tic;
end
                [v,k] = max( (1 + rrr( 1:length( C0 ) )) .* (C0 + CV*d) );line_runtime=toc; runtime_info(407, :) = runtime_info(407, :) + [0 line_runtime 1]; tic;
                v0( t ) = C0( k );line_runtime=toc; runtime_info(408, :) = runtime_info(408, :) + [0 line_runtime 1]; tic;
                k = h( k );line_runtime=toc; runtime_info(409, :) = runtime_info(409, :) + [0 line_runtime 1]; tic;
    else
                k = h( 1 );line_runtime=toc; runtime_info(411, :) = runtime_info(411, :) + [0 line_runtime 1]; tic;
                v0( t ) = board( M( k ) ) - board( F( k ) );line_runtime=toc; runtime_info(412, :) = runtime_info(412, :) + [0 line_runtime 1]; tic;
end
            moves( t, : ) = MV( k, : );line_runtime=toc; runtime_info(414, :) = runtime_info(414, :) + [0 line_runtime 1]; tic;
        T0 = T( k );line_runtime=toc; runtime_info(415, :) = runtime_info(415, :) + [0 line_runtime 1]; tic;
            F0 = F( k );line_runtime=toc; runtime_info(416, :) = runtime_info(416, :) + [0 line_runtime 1]; tic;
            M0 = M( k );line_runtime=toc; runtime_info(417, :) = runtime_info(417, :) + [0 line_runtime 1]; tic;
        t = t + 1;line_runtime=toc; runtime_info(418, :) = runtime_info(418, :) + [0 line_runtime 1]; tic;
            Bmax( T0 ) = board( F0 );line_runtime=toc; runtime_info(419, :) = runtime_info(419, :) + [0 line_runtime 1]; tic;
            Bmax( F0 ) = 0;line_runtime=toc; runtime_info(420, :) = runtime_info(420, :) + [0 line_runtime 1]; tic;
            Bmax( M0 ) = 0;line_runtime=toc; runtime_info(421, :) = runtime_info(421, :) + [0 line_runtime 1]; tic;
            board( T0 ) = board( F0 );line_runtime=toc; runtime_info(422, :) = runtime_info(422, :) + [0 line_runtime 1]; tic;
            Bzero( T0 ) = false;line_runtime=toc; runtime_info(423, :) = runtime_info(423, :) + [0 line_runtime 1]; tic;
            Bpos( T0 ) = true;line_runtime=toc; runtime_info(424, :) = runtime_info(424, :) + [0 line_runtime 1]; tic;
            board( F0 ) = 0;line_runtime=toc; runtime_info(425, :) = runtime_info(425, :) + [0 line_runtime 1]; tic;
            Bzero( F0 ) = true;line_runtime=toc; runtime_info(426, :) = runtime_info(426, :) + [0 line_runtime 1]; tic;
            Bpos( F0 ) = false;line_runtime=toc; runtime_info(427, :) = runtime_info(427, :) + [0 line_runtime 1]; tic;
            board( M0 ) = 0;line_runtime=toc; runtime_info(428, :) = runtime_info(428, :) + [0 line_runtime 1]; tic;
            Bpos( M0 ) = false;line_runtime=toc; runtime_info(429, :) = runtime_info(429, :) + [0 line_runtime 1]; tic;
            Bzero( M0 ) = true;line_runtime=toc; runtime_info(430, :) = runtime_info(430, :) + [0 line_runtime 1]; tic;
        FF = [ F0, M0, T0 ];line_runtime=toc; runtime_info(431, :) = runtime_info(431, :) + [0 line_runtime 1]; tic;
        originatingMoves = moveid1( FF, : );line_runtime=toc; runtime_info(432, :) = runtime_info(432, :) + [0 line_runtime 1]; tic;
        originatingMoves = originatingMoves( originatingMoves>0 );line_runtime=toc; runtime_info(433, :) = runtime_info(433, :) + [0 line_runtime 1]; tic;
        jumpedMoves = moveid2( FF, : );line_runtime=toc; runtime_info(434, :) = runtime_info(434, :) + [0 line_runtime 1]; tic;
        jumpedMoves = jumpedMoves( jumpedMoves>0 );line_runtime=toc; runtime_info(435, :) = runtime_info(435, :) + [0 line_runtime 1]; tic;
        terminatingMoves = moveid3( FF, : );line_runtime=toc; runtime_info(436, :) = runtime_info(436, :) + [0 line_runtime 1]; tic;
        terminatingMoves = terminatingMoves( terminatingMoves>0 );line_runtime=toc; runtime_info(437, :) = runtime_info(437, :) + [0 line_runtime 1]; tic;
        allMoves = [ originatingMoves; jumpedMoves; terminatingMoves ];line_runtime=toc; runtime_info(438, :) = runtime_info(438, :) + [0 line_runtime 1]; tic;
        validMoves( allMoves ) = Bpos( F( allMoves ) ) & Bzero( T( allMoves ) ) & Bpos( M( allMoves ) );line_runtime=toc; runtime_info(439, :) = runtime_info(439, :) + [0 line_runtime 1]; tic;
    h = find( validMoves );line_runtime=toc; runtime_info(440, :) = runtime_info(440, :) + [0 line_runtime 1]; tic;
end
    v0 = cumsum( v0 );line_runtime=toc; runtime_info(442, :) = runtime_info(442, :) + [0 line_runtime 1]; tic;
    [v,t] = max( v0 );line_runtime=toc; runtime_info(443, :) = runtime_info(443, :) + [0 line_runtime 1]; tic;
        moves = moves( 1:t, : );line_runtime=toc; runtime_info(444, :) = runtime_info(444, :) + [0 line_runtime 1]; tic;
end
function [moves,v] = subsoltweak(board,F,T,M,pegCount,TT,MM,MV,MVV,moveid1,moveid2,moveid3)
eval('if exist(''runtime_info'')==0; global runtime_info; end; tic;')
    moves = zeros( pegCount - 1, 4 );line_runtime=toc; runtime_info(447, :) = runtime_info(447, :) + [0 line_runtime 1]; tic;
    v0 = zeros( pegCount - 1, 1 );line_runtime=toc; runtime_info(448, :) = runtime_info(448, :) + [0 line_runtime 1]; tic;
        Bzero = ~board;line_runtime=toc; runtime_info(449, :) = runtime_info(449, :) + [0 line_runtime 1]; tic;
        Bpos = board>0;line_runtime=toc; runtime_info(450, :) = runtime_info(450, :) + [0 line_runtime 1]; tic;
        Bmax = max( board, 0 );line_runtime=toc; runtime_info(451, :) = runtime_info(451, :) + [0 line_runtime 1]; tic;
            hs = (Bpos( F ) & Bzero( T ) & Bpos( M ));line_runtime=toc; runtime_info(452, :) = runtime_info(452, :) + [0 line_runtime 1]; tic;
        h = find( hs );line_runtime=toc; runtime_info(453, :) = runtime_info(453, :) + [0 line_runtime 1]; tic;
                C0 = board( M( h ) ) - board( F( h ) );line_runtime=toc; runtime_info(454, :) = runtime_info(454, :) + [0 line_runtime 1]; tic;
        [CV,kc] = max( Bmax( MM( h, : ) ) .* Bzero( TT( h, : ) ), [  ], 2 );line_runtime=toc; runtime_info(455, :) = runtime_info(455, :) + [0 line_runtime 1]; tic;
        [v,k] = max( C0 + CV );line_runtime=toc; runtime_info(456, :) = runtime_info(456, :) + [0 line_runtime 1]; tic;
    v0( 1 ) = C0( k );line_runtime=toc; runtime_info(457, :) = runtime_info(457, :) + [0 line_runtime 1]; tic;
                k = h( k );line_runtime=toc; runtime_info(458, :) = runtime_info(458, :) + [0 line_runtime 1]; tic;
    moves( 1, : ) = MV( k, : );line_runtime=toc; runtime_info(459, :) = runtime_info(459, :) + [0 line_runtime 1]; tic;
            F0 = F( k );line_runtime=toc; runtime_info(460, :) = runtime_info(460, :) + [0 line_runtime 1]; tic;
    t = 2;line_runtime=toc; runtime_info(461, :) = runtime_info(461, :) + [0 line_runtime 1]; tic;
        T0 = T( k );line_runtime=toc; runtime_info(462, :) = runtime_info(462, :) + [0 line_runtime 1]; tic;
            FF = [ F0, M( k ), T0 ];line_runtime=toc; runtime_info(463, :) = runtime_info(463, :) + [0 line_runtime 1]; tic;
            M0 = M( k );line_runtime=toc; runtime_info(464, :) = runtime_info(464, :) + [0 line_runtime 1]; tic;
            Bmax( T0 ) = board( F0 );line_runtime=toc; runtime_info(465, :) = runtime_info(465, :) + [0 line_runtime 1]; tic;
            Bmax( F0 ) = 0;line_runtime=toc; runtime_info(466, :) = runtime_info(466, :) + [0 line_runtime 1]; tic;
            Bmax( M0 ) = 0;line_runtime=toc; runtime_info(467, :) = runtime_info(467, :) + [0 line_runtime 1]; tic;
            board( T0 ) = board( F0 );line_runtime=toc; runtime_info(468, :) = runtime_info(468, :) + [0 line_runtime 1]; tic;
            Bzero( T0 ) = false;line_runtime=toc; runtime_info(469, :) = runtime_info(469, :) + [0 line_runtime 1]; tic;
            Bpos( T0 ) = true;line_runtime=toc; runtime_info(470, :) = runtime_info(470, :) + [0 line_runtime 1]; tic;
            board( F0 ) = 0;line_runtime=toc; runtime_info(471, :) = runtime_info(471, :) + [0 line_runtime 1]; tic;
            Bzero( F0 ) = true;line_runtime=toc; runtime_info(472, :) = runtime_info(472, :) + [0 line_runtime 1]; tic;
            Bpos( F0 ) = false;line_runtime=toc; runtime_info(473, :) = runtime_info(473, :) + [0 line_runtime 1]; tic;
            board( M0 ) = 0;line_runtime=toc; runtime_info(474, :) = runtime_info(474, :) + [0 line_runtime 1]; tic;
            Bpos( M0 ) = false;line_runtime=toc; runtime_info(475, :) = runtime_info(475, :) + [0 line_runtime 1]; tic;
            Bzero( M0 ) = true;line_runtime=toc; runtime_info(476, :) = runtime_info(476, :) + [0 line_runtime 1]; tic;
        originatingMoves = moveid1( FF, : );line_runtime=toc; runtime_info(477, :) = runtime_info(477, :) + [0 line_runtime 1]; tic;
        originatingMoves = originatingMoves( originatingMoves>0 );line_runtime=toc; runtime_info(478, :) = runtime_info(478, :) + [0 line_runtime 1]; tic;
        jumpedMoves = moveid2( FF, : );line_runtime=toc; runtime_info(479, :) = runtime_info(479, :) + [0 line_runtime 1]; tic;
        jumpedMoves = jumpedMoves( jumpedMoves>0 );line_runtime=toc; runtime_info(480, :) = runtime_info(480, :) + [0 line_runtime 1]; tic;
        terminatingMoves = moveid3( FF, : );line_runtime=toc; runtime_info(481, :) = runtime_info(481, :) + [0 line_runtime 1]; tic;
        terminatingMoves = terminatingMoves( terminatingMoves>0 );line_runtime=toc; runtime_info(482, :) = runtime_info(482, :) + [0 line_runtime 1]; tic;
        allMoves = [ originatingMoves; jumpedMoves; terminatingMoves ];line_runtime=toc; runtime_info(483, :) = runtime_info(483, :) + [0 line_runtime 1]; tic;
        hs( allMoves ) = Bpos( F( allMoves ) ) & Bzero( T( allMoves ) ) & Bpos( M( allMoves ) );line_runtime=toc; runtime_info(484, :) = runtime_info(484, :) + [0 line_runtime 1]; tic;
        h = find( hs );line_runtime=toc; runtime_info(485, :) = runtime_info(485, :) + [0 line_runtime 1]; tic;
    while ~isempty( h )
                c = find( F( h )==T0 );line_runtime=toc; runtime_info(487, :) = runtime_info(487, :) + [0 line_runtime 1]; tic;
            if ~isempty( c )
                h = h( c );line_runtime=toc; runtime_info(489, :) = runtime_info(489, :) + [0 line_runtime 1]; tic;
                C0 = board( M( h ) );line_runtime=toc; runtime_info(490, :) = runtime_info(490, :) + [0 line_runtime 1]; tic;
    else
                C0 = board( M( h ) ) - board( F( h ) );line_runtime=toc; runtime_info(492, :) = runtime_info(492, :) + [0 line_runtime 1]; tic;
end
        [CV,kc] = max( Bmax( MM( h, : ) ) .* Bzero( TT( h, : ) ), [  ], 2 );line_runtime=toc; runtime_info(494, :) = runtime_info(494, :) + [0 line_runtime 1]; tic;
        [v,k] = max( C0 + CV );line_runtime=toc; runtime_info(495, :) = runtime_info(495, :) + [0 line_runtime 1]; tic;
                v0( t ) = C0( k );line_runtime=toc; runtime_info(496, :) = runtime_info(496, :) + [0 line_runtime 1]; tic;
        cv = CV( k );line_runtime=toc; runtime_info(497, :) = runtime_info(497, :) + [0 line_runtime 1]; tic;
        kc = kc( k );line_runtime=toc; runtime_info(498, :) = runtime_info(498, :) + [0 line_runtime 1]; tic;
                k = h( k );line_runtime=toc; runtime_info(499, :) = runtime_info(499, :) + [0 line_runtime 1]; tic;
            moves( t, : ) = MV( k, : );line_runtime=toc; runtime_info(500, :) = runtime_info(500, :) + [0 line_runtime 1]; tic;
            F0 = F( k );line_runtime=toc; runtime_info(501, :) = runtime_info(501, :) + [0 line_runtime 1]; tic;
        t = t + 1;line_runtime=toc; runtime_info(502, :) = runtime_info(502, :) + [0 line_runtime 1]; tic;
        if ~cv
        T0 = T( k );line_runtime=toc; runtime_info(504, :) = runtime_info(504, :) + [0 line_runtime 1]; tic;
            FF = [ F0, M( k ), T0 ];line_runtime=toc; runtime_info(505, :) = runtime_info(505, :) + [0 line_runtime 1]; tic;
    else
            T0 = TT( k, kc );line_runtime=toc; runtime_info(507, :) = runtime_info(507, :) + [0 line_runtime 1]; tic;
            M0 = MM( k, kc );line_runtime=toc; runtime_info(508, :) = runtime_info(508, :) + [0 line_runtime 1]; tic;
            moves( t, : ) = MVV{ kc }( k, : );line_runtime=toc; runtime_info(509, :) = runtime_info(509, :) + [0 line_runtime 1]; tic;
            FF = [ F0, M( k ), M0, T0 ];line_runtime=toc; runtime_info(510, :) = runtime_info(510, :) + [0 line_runtime 1]; tic;
            v0( t ) = cv;line_runtime=toc; runtime_info(511, :) = runtime_info(511, :) + [0 line_runtime 1]; tic;
            board( M0 ) = 0;line_runtime=toc; runtime_info(512, :) = runtime_info(512, :) + [0 line_runtime 1]; tic;
            Bzero( M0 ) = true;line_runtime=toc; runtime_info(513, :) = runtime_info(513, :) + [0 line_runtime 1]; tic;
            Bpos( M0 ) = false;line_runtime=toc; runtime_info(514, :) = runtime_info(514, :) + [0 line_runtime 1]; tic;
            Bmax( M0 ) = 0;line_runtime=toc; runtime_info(515, :) = runtime_info(515, :) + [0 line_runtime 1]; tic;
        t = t + 1;line_runtime=toc; runtime_info(516, :) = runtime_info(516, :) + [0 line_runtime 1]; tic;
end
            M0 = M( k );line_runtime=toc; runtime_info(518, :) = runtime_info(518, :) + [0 line_runtime 1]; tic;
            Bmax( T0 ) = board( F0 );line_runtime=toc; runtime_info(519, :) = runtime_info(519, :) + [0 line_runtime 1]; tic;
            Bmax( F0 ) = 0;line_runtime=toc; runtime_info(520, :) = runtime_info(520, :) + [0 line_runtime 1]; tic;
            Bmax( M0 ) = 0;line_runtime=toc; runtime_info(521, :) = runtime_info(521, :) + [0 line_runtime 1]; tic;
            board( T0 ) = board( F0 );line_runtime=toc; runtime_info(522, :) = runtime_info(522, :) + [0 line_runtime 1]; tic;
            Bzero( T0 ) = false;line_runtime=toc; runtime_info(523, :) = runtime_info(523, :) + [0 line_runtime 1]; tic;
            Bpos( T0 ) = true;line_runtime=toc; runtime_info(524, :) = runtime_info(524, :) + [0 line_runtime 1]; tic;
            board( F0 ) = 0;line_runtime=toc; runtime_info(525, :) = runtime_info(525, :) + [0 line_runtime 1]; tic;
            Bzero( F0 ) = true;line_runtime=toc; runtime_info(526, :) = runtime_info(526, :) + [0 line_runtime 1]; tic;
            Bpos( F0 ) = false;line_runtime=toc; runtime_info(527, :) = runtime_info(527, :) + [0 line_runtime 1]; tic;
            board( M0 ) = 0;line_runtime=toc; runtime_info(528, :) = runtime_info(528, :) + [0 line_runtime 1]; tic;
            Bpos( M0 ) = false;line_runtime=toc; runtime_info(529, :) = runtime_info(529, :) + [0 line_runtime 1]; tic;
            Bzero( M0 ) = true;line_runtime=toc; runtime_info(530, :) = runtime_info(530, :) + [0 line_runtime 1]; tic;
        originatingMoves = moveid1( FF, : );line_runtime=toc; runtime_info(531, :) = runtime_info(531, :) + [0 line_runtime 1]; tic;
        originatingMoves = originatingMoves( originatingMoves>0 );line_runtime=toc; runtime_info(532, :) = runtime_info(532, :) + [0 line_runtime 1]; tic;
        jumpedMoves = moveid2( FF, : );line_runtime=toc; runtime_info(533, :) = runtime_info(533, :) + [0 line_runtime 1]; tic;
        jumpedMoves = jumpedMoves( jumpedMoves>0 );line_runtime=toc; runtime_info(534, :) = runtime_info(534, :) + [0 line_runtime 1]; tic;
        terminatingMoves = moveid3( FF, : );line_runtime=toc; runtime_info(535, :) = runtime_info(535, :) + [0 line_runtime 1]; tic;
        terminatingMoves = terminatingMoves( terminatingMoves>0 );line_runtime=toc; runtime_info(536, :) = runtime_info(536, :) + [0 line_runtime 1]; tic;
        allMoves = [ originatingMoves; jumpedMoves; terminatingMoves ];line_runtime=toc; runtime_info(537, :) = runtime_info(537, :) + [0 line_runtime 1]; tic;
        hs( allMoves ) = Bpos( F( allMoves ) ) & Bzero( T( allMoves ) ) & Bpos( M( allMoves ) );line_runtime=toc; runtime_info(538, :) = runtime_info(538, :) + [0 line_runtime 1]; tic;
        h = find( hs );line_runtime=toc; runtime_info(539, :) = runtime_info(539, :) + [0 line_runtime 1]; tic;
end
    vv0 = cumsum( v0 );line_runtime=toc; runtime_info(541, :) = runtime_info(541, :) + [0 line_runtime 1]; tic;
    [v,t] = max( vv0 );line_runtime=toc; runtime_info(542, :) = runtime_info(542, :) + [0 line_runtime 1]; tic;
        moves = moves( 1:t, : );line_runtime=toc; runtime_info(543, :) = runtime_info(543, :) + [0 line_runtime 1]; tic;
end

Contact us