// 
init_arr %hod (1) 845, 206 1265456                //  
init_arr %LevVerh (1) 849, 259

init_arr %skill (1) 649, 576 930, 692                 //   
init_arr %GetImage (1) 726, 210 767, 227            //     
set %pathimages [1] C:\5            //   
set #waitskill 500                                //    

//   
init_arr %imya (1)  1 11000814
init_arr %imya (2)  5 1638562
init_arr %imya (3) Ƹ 3 1439487
init_arr %imya (4)  1 13172735
init_arr %imya (5)  1 9086385

set #wait 700    // ,   ,    

set #workwin 0   // 0 -   , 1-  

if  #workwin = 0
    set #handle 2
    init_arr %workwindow (1) 0 0             //  !!
else
    init_arr %workwindow (1) 0 0           //      
    set #handle findwindow ()
end_if

gosub begin

:start
gosub poisk                   //  
set size(%result)                        //     
gosub mp    //    
if  size(%result) > 0         //   
    // hint (14 clBlue 423, 301 (%result [1 1]))    //     
    if  %result [1 1] > 64    //    64
        gosub 
        gosub 
    else
        if  %result [1 1] > 49    //    64,   49
            gosub 
        end_if
    end_if
end_if

gosub square                  // 
if  #square = 0               //     
    gosub krest               // 
    if  #krest = 0            //     
        gosub line3                   //  
        gosub showresult              //    
        gosub hod                     //  
        // 
        left #x1 #y1 5 5 5 5
        wait 200 + random(200)
        left #x2 #y2 5 5 5 5
        wait 200 + random(200)
    end_if
end_if
left 133, 575 20 20 20 20     //    ,      
wait 2000
goto start
End_script

:begin
    set linedelay 0
    if  workwindow = 0
        log    
        End_script
    end_if
    log open
    wait 100
    //set windowpos 0 0 500 400 loghandle
    log clear
    log mode compact


    set $regexp3_1 "(\d)\1"
    set $regexp3_2 "(\d)\d\1(?!\1)"

    set #startX %LevVerh [1 1] + %workwindow [1 1]
    set #startY %LevVerh [1 2] + %workwindow [1 2]
    set #stepX 41
    set #stepY 41
    set #endX #startX + #stepX * 5
    set #endY #startY + #stepY * 5
    set #hodx %hod [1 1] + %workwindow [1 1]
    set #hody %hod [1 2] + %workwindow [1 2]

    set %kvadrat [1] LoadImage(%pathimages [1]\kvadrat.bmp)
    set %krest [1] LoadImage(%pathimages [1]\krest.bmp)
    set %berserk [1] LoadImage(%pathimages [1]\berserk.bmp)
    set %thunder [1] LoadImage(%pathimages [1]\thunder.bmp)

    init_arr %picture 0 1 2 3 4 5 6 7 8 9       //   (0.bmp, 1.bmp  . .)
    init_arr %symbol 0 1 2 3 4 5 6 7 8 9        //   , . .  0.bmp  0
    set $path %pathimages [1]                     //   
    set $bmp "*.bmp*"                           //  
    set #deltaY 8                               //    (   )
    set #deltaspace 10                          //    ,        
    set #accuracy 100                            //    Findimage
    set #deviation 1                           //     Findimage
    set #waitimage 2                                 //    ,      ,   
    set #timeproc 3000                          //  ( )   ,  0          1 
    dir (%path $path $bmp)
    set #GetStartX %GetImage [1 1]
    set #GetStartY %GetImage [1 2]
    set #GetEndX %GetImage [1 3]
    set #GetEndY %GetImage [1 4]

    //    
    if  size(%path) > 0                  //   
        for #i 1 size(%path)
            for #j 1 size(%picture)
                if  %path [#i 3] = %picture [#j]
                    set #n #n + 1
                    set %image [#n] LoadImage(%path [#i 1])
                    set %number [#n] %symbol [#j]
                    break
                end_if
            end_for
        end_for
    else
        log  : $path    
        log  
        stop_script
    end_if
return

:poisk
    set size(%left)
    set size(%left2)
    set #result 0
    if  #workwin = 0
        while_not #hodx #hody %hod [1 3]    //    
            wait 100
        end_while
    else
        while_not color (#hodx #hody #handle) = %hod [1 3]    //   
            wait 100
        end_while
    end_if
    wait 300

    //  
    set #a findcolor (#startX #startY #endX #endY #stepX #stepY (%imya [1 3] %imya [2 3] %imya [3 3] %imya [4 3] %imya [5 3]) %arr #handle)
    //save_array %arr C:\Users\abc\Desktop\Setkafind.txt
    if  #a > 0
        set #z 0
        for #i 1 6
            for #j 1 6
                set #z #z + 1
                switch %arr [#z 3]
                    case %imya [1 3]: set %a [#i #j] 1       // 
                        break
                    case %imya [2 3]: set %a [#i #j] 2         // 
                        break
                    case %imya [3 3]: set %a [#i #j] 3         // 
                        break
                    case %imya [4 3]: set %a [#i #j] 4       // 
                        break
                    case %imya [5 3]: set %a [#i #j] 5          // 
                end_switch
            end_for
        end_for
        // save_array %a C:\Users\abc\Desktop\Setka1111.txt    // 
    else
        goto start
    end_if
    //   
    wait #wait
    set #resultat 0

    set #a1 findcolor (#startX #startY #endX #endY #stepX #stepY (%imya [1 3] %imya [2 3] %imya [3 3] %imya [4 3] %imya [5 3]) %arr1 #handle)
    //save_array %arr C:\Users\abc\Desktop\Setkafind1.txt
    if  #a1 > 0
        set #z 0
        for #i 1 6
            for #j 1 6
                set #z #z + 1
                switch %arr1 [#z 3]
                    case %imya [1 3]: set %a1 [#i #j] 1       // 
                        break
                    case %imya [2 3]: set %a1 [#i #j] 2         // 
                        break
                    case %imya [3 3]: set %a1 [#i #j] 3         // 
                        break
                    case %imya [4 3]: set %a1 [#i #j] 4       // 
                        break
                    case %imya [5 3]: set %a1 [#i #j] 5          // 
                end_switch
            end_for
        end_for
        //save_array %a1 C:\Users\abc\Desktop\Setka1.txt    // 
    end_if

    //  
    for #i 1 6
        set #z 0
        for #j 1 6
            set #z #z + 1
            if  %a [#i #j] != %a1 [#i #j]
                set #resultat 1
                break 2
            end_if
        end_for
    end_for
    if  #resultat = 1      //    
        goto poisk
    end_if

    for #i 1 size(%a)
        init_arr %b (#i)  %a[1 #i] %a[2 #i] %a[3 #i] %a[4 #i] %a[5 #i] %a[6 #i]
    end_for
    log clear
return

proc line3_1 %a #i $string $newstring #del $regexp #flagcolrow
    set #n regexp (#pos $hitstring $newstring $regexp)
    if  #n > 0
        set #pos #del + #pos
        set $newstring delete($string 1 #pos)
        if  size($newstring) > 1
            if  #flagcolrow = 0
                call line3_1 %a #i $string $newstring #pos $regexp 0
            else
                call line3_1 %a #i $string $newstring #pos $regexp 1
            end_if
        end_if
    end_if
    if  #n > 0
        set #z copy($hitstring 1 1)
        set #pos2 #pos + 2
        set #pos3 #pos + 3
        set #pos4 #pos + 4
        set #pos_1 #pos - 1
        set #pos_2 #pos - 2
        set #pos_3 #pos - 3
        if  #i = 1
            // 1
            if  #pos < 3 and %a [#i #pos3] = #z and %a [#i #pos4] = #z and %a [2 #pos2] = #z
                call colrow #i #pos2 2 #pos2 #flagcolrow 5 current_script #z     // 11011
            end_if
            if  #pos < 4 and %a [#i #pos3] = #z and %a [#i #pos4] != #z and %a [2 #pos2] = #z
                call colrow #i #pos2 2 #pos2 #flagcolrow 4 current_script #z     // 1101
            end_if
            if  #pos < 4 and %a [#i #pos3] = #z
                call colrow #i #pos3 #i #pos2 #flagcolrow 3 current_script #z     //  3   11_1
            end_if
            if  #pos < 5 and %a [#i #pos3] != #z and %a [2 #pos2] = #z
                call colrow #i #pos2 2 #pos2 #flagcolrow 3 current_script #z     //  3  11   1
            end_if
            if  #pos = 3
                if  %a [#i #pos_2] = #z and %a [2 #pos_1] = #z
                    call colrow 2 #pos_1 #i #pos_1 #flagcolrow 4 current_script #z     // 101123
                end_if
            end_if
            if  #pos > 3
                if  %a [#i #pos_2] = #z and %a [#i #pos_3] != #z and %a [2 #pos_1] = #z
                    call colrow #i #pos_1 2 #pos_1 #flagcolrow 4 current_script #z     // 210113  231011
                end_if
            end_if
            if  #pos > 2
                if  %a [#i #pos_2] = #z
                    call colrow #i #pos_2 #i #pos_1 #flagcolrow 3 current_script #z     // 1_11
                end_if
                if  %a [#i #pos_2] != #z and %a [2 #pos_1] = #z
                    call colrow 2 #pos_1 #i #pos_1 #flagcolrow 3 current_script #z     // 201134   1
                end_if
            end_if
            if  #pos = 2
                if  %a [2 #pos_1] = #z
                    call colrow #i #pos_1 2 #pos_1 #flagcolrow 3 current_script #z     // 11    1
                end_if
            end_if
        else
            if  #i = 6          // 6
                if  #pos < 3 and %a [#i #pos3] = #z and %a [#i #pos4] = #z and %a [5 #pos2] = #z
                    call colrow #i #pos2 5 #pos2 #flagcolrow 5 current_script #z     // 11011
                end_if
                if  #pos < 4 and %a [#i #pos3] = #z and %a [#i #pos4] != #z and %a [5 #pos2] = #z
                    call colrow #i #pos2 5 #pos2 #flagcolrow 4 current_script #z     // 1101
                end_if
                if  #pos < 4 and %a [#i #pos3] = #z
                    call colrow #i #pos3 #i #pos2 #flagcolrow 3 current_script #z     //  3   11_1
                end_if
                if  #pos < 5 and %a [#i #pos3] != #z and %a [5 #pos2] = #z
                    call colrow #i #pos2 5 #pos2 #flagcolrow 3 current_script #z     //  3  11   1
                end_if
                if  #pos = 3
                    if  %a [#i #pos_2] = #z and %a [5 #pos_1] = #z
                        call colrow 5 #pos_1 #i #pos_1 #flagcolrow 4 current_script #z     // 101123
                    end_if
                end_if
                if  #pos > 3
                    if  %a [#i #pos_2] = #z and %a [#i #pos_3] != #z and %a [5 #pos_1] = #z
                        call colrow #i #pos_1 5 #pos_1 #flagcolrow 4 current_script #z     // 210113  231011
                    end_if
                end_if
                if  #pos > 2
                    if  %a [#i #pos_2] = #z
                        call colrow #i #pos_2 #i #pos_1 #flagcolrow 3 current_script #z     // 1_11
                    end_if
                    if  %a [#i #pos_2] != #z and %a [5 #pos_1] = #z
                        call colrow #i #pos_1 5 #pos_1 #flagcolrow 3 current_script #z     // 201134   1
                    end_if
                end_if
                if  #pos = 2
                    if  %a [5 #pos_1] = #z
                        call colrow 5 #pos_1 #i #pos_1 #flagcolrow 3 current_script #z     // 11    1
                    end_if
                end_if
            else                // 2345
                set #col1 #i + 1
                set #col2 #i - 1
                if  #pos < 3 and %a [#i #pos3] = #z and %a [#i #pos4] = #z and %a [#col1 #pos2] = #z
                    call colrow #i #pos2 #col1 #pos2 #flagcolrow 5 current_script #z     // 11011
                end_if
                if  #pos < 3 and %a [#i #pos3] = #z and %a [#i #pos4] = #z and %a [#col2 #pos2] = #z
                    call colrow #i #pos2 #col2 #pos2 #flagcolrow 5 current_script #z     // 11011
                end_if
                if  #pos < 4 and %a [#i #pos3] = #z and %a [#i #pos4] != #z and %a [#col1 #pos2] = #z
                    call colrow #i #pos2 #col1 #pos2 #flagcolrow 4 current_script #z     // 1101
                end_if
                if  #pos < 4 and %a [#i #pos3] = #z and %a [#i #pos4] != #z and %a [#col2 #pos2] = #z
                    call colrow #i #pos2 #col2 #pos2 #flagcolrow 4 current_script #z     // 1101
                end_if
                if  #pos < 4 and %a [#i #pos3] = #z
                    call colrow #i #pos3 #i #pos2 #flagcolrow 3 current_script #z     //  3   11_1
                end_if
                if  #pos < 5 and %a [#i #pos3] != #z and %a [#col1 #pos2] = #z
                    call colrow #i #pos2 #col1 #pos2 #flagcolrow 3 current_script #z     //  3  11   1
                end_if
                if  #pos < 5 and %a [#i #pos3] != #z and %a [#col2 #pos2] = #z

                    call colrow #i #pos2 #col2 #pos2 #flagcolrow 3 current_script #z     //  3  11   1
                end_if
                if  #pos = 3
                    if  %a [#i #pos_2] = #z and %a [#col1 #pos_1] = #z
                        call colrow #col1 #pos_1 #i #pos_1 #flagcolrow 4 current_script #z     // 101123
                    end_if
                    if  %a [#i #pos_2] = #z and %a [#col2 #pos_1] = #z
                        call colrow #col2 #pos_1 #i #pos_1 #flagcolrow 4 current_script #z     // 101123
                    end_if
                end_if
                if  #pos > 3
                    if  %a [#i #pos_2] = #z and %a [#i #pos_3] != #z and %a [#col1 #pos_1] = #z
                        call colrow #i #pos_1 #col1 #pos_1 #flagcolrow 4 current_script #z     // 210113  231011
                    end_if
                    if  %a [#i #pos_2] = #z and %a [#i #pos_3] != #z and %a [#col2 #pos_1] = #z
                        call colrow #i #pos_1 #col2 #pos_1 #flagcolrow 4 current_script #z     // 210113  231011
                    end_if
                end_if
                if  #pos > 2
                    if  %a [#i #pos_2] = #z
                        call colrow #i #pos_2 #i #pos_1 #flagcolrow 3 current_script #z     // 1_11
                    end_if
                    if  %a [#i #pos_2] != #z and %a [#col1 #pos_1] = #z
                        call colrow #col1 #pos_1 #i #pos_1 #flagcolrow 3 current_script #z     // 201134   1
                    end_if
                    if  %a [#i #pos_2] != #z and %a [#col2 #pos_1] = #z
                        call colrow #col2 #pos_1 #i #pos_1 #flagcolrow 3 current_script #z     // 201134   1
                    end_if
                end_if
                if  #pos = 2
                    if  %a [#col1 #pos_1] = #z
                        call colrow #col1 #pos_1 #i #pos_1 #flagcolrow 3 current_script #z     // 11    1
                    end_if
                    if  %a [#col2 #pos_1] = #z
                        call colrow #col2 #pos_1 #i #pos_1  #flagcolrow 3 current_script #z     // 11    1
                    end_if
                end_if
            end_if
        end_if
    end_if
end_proc

proc line3_2 %a #i $string $newstring #del $regexp #flagcolrow
    set #n regexp (#pos $hitstring $newstring $regexp)
    if  #n > 0
        set #pos #del + #pos
        set $newstring delete($string 1 #pos)
        if  size($newstring) > 2
            if  #flagcolrow = 0
                call line3_2 %a #i $string $newstring #pos $regexp 0
            else
                call line3_2 %a #i $string $newstring #pos $regexp 1
            end_if
        end_if
    end_if
    if  #n > 0
        set #z copy($hitstring 1 1)
        set #pos1 #pos + 1
        if  #pos = 1
            set #pos2 #pos + 1
        else
            set #pos2 #pos - 1
        end_if
        if  #i = 1               // 1
            if  %a [2 #pos1] = #z and %a [#i #pos2] != #z
                call colrow #i #pos1 2 #pos1 #flagcolrow 3 current_script #z
            end_if
        else
            if  #i = 6          // 6
                if  %a [5 #pos1] = #z and %a [#i #pos2] != #z
                    call colrow #i #pos1 5 #pos1 #flagcolrow 3 current_script #z
                end_if
            else                // 2345
                set #col1 #i + 1
                set #col2 #i - 1
                if  %a [#col1 #pos1] = #z and %a [#i #pos2] != #z
                    call colrow #i #pos1 #col1 #pos1 #flagcolrow 3 current_script #z
                end_if
                if  %a [#col2 #pos1] = #z and %a [#i #pos2] != #z
                    call colrow #i #pos1 #col2 #pos1 #flagcolrow 3 current_script #z
                end_if
            end_if
        end_if
    end_if
end_proc

proc colrow #col1 #row1 #col2 #row2 #flagcolrow #number #cur #z
    set #result.#cur 1
    log mode compact
    if  #flagcolrow = 0
        set #size size(%left.#cur)
        set #size #size + 1
        set %left.#cur [#size 1] #row1
        set %left.#cur [#size 2] #col1
        set %left.#cur [#size 3] #row2
        set %left.#cur [#size 4] #col2
        set %left.#cur [#size 5] #z
        set %left.#cur [#size 6] #number
        set %left.#cur [#size 7] %imya.#cur [#z 1]
    else
        set #size size(%left.#cur)
        set #size #size + 1
        set %left.#cur [#size 1] #col1
        set %left.#cur [#size 2] #row1
        set %left.#cur [#size 3] #col2
        set %left.#cur [#size 4] #row2
        set %left.#cur [#size 5] #z
        set %left.#cur [#size 6] #number
        set %left.#cur [#size 7] %imya.#cur [#z 1]
    end_if
end_proc

:showresult
    if  size(%left) > 0
        for #i 1 size(%left)
            log   %left [#i 2] %left [#i 1]  %left [#i 4] %left [#i 3]      %left [#i 6]    %left [#i 7]
        end_for
    else
        log   
    end_if
    sort_array %left 6 dec
    //save_array %left C:\Users\abc\Desktop\Resultleft.txt
return

:line3
    for #i 1 size(%a)
        set $string %a [#i]
        call line3_1 %a #i $string $string 0 $regexp3_1 0
        call line3_2 %a #i $string $string 0 $regexp3_2 0
    end_for
    set %a %b
    for #i 1 size(%a)
        set $string %a [#i]
        call line3_1 %a #i $string $string 0 $regexp3_1 1
        call line3_2 %a #i $string $string 0 $regexp3_2 1
    end_for
return

:hod
    if  %left [1 6] > 4
        sort_array %left 5
        sort_array %left 6 dec
        set #summa1 %left [1 6] * %imya [%left [1 5] 2]
        log
        log : %left [1 2] %left [1 1]  %left [1 4] %left [1 3]      %left [1 6] %left [1 7]    : #summa1
        init_arr %xy (1) %left [1 2] %left [1 1] %left [1 4] %left [1 3]
    else
        for #i 1 eval (size(%left) - 1)
            set #hod1 %left[#i 2]%left[#i 1]%left[#i 4]%left[#i 3]
            set #jj #i + 1
            for #j #jj size(%left)
                set #hod2 %left[#j 4]%left[#j 3]%left[#j 2]%left[#j 1]
                set #hod3 %left[#j 2]%left[#j 1]%left[#j 4]%left[#j 3]
                if  #hod1 = #hod2 or #hod1 = #hod3
                    set #zz #zz + 1
                    set #summa %left [#i 6] * %imya [%left [#i 5] 2] + %left [#j 6] * %imya [%left [#j 5] 2]
                    init_arr %left2 (#zz) %left[#i 2] %left[#i 1] %left[#i 4] %left[#i 3] %left[#i 6] %imya[%left[#i 5] 1] %left[#j 6] %imya[%left[#j 5] 1] #summa
                    if  %left2 [#zz 6] = %left2 [#zz 8]
                        set %left2 [#zz 9] #summa - #summa / 6
                    end_if
                end_if
            end_for
        end_for
        for #k 1 size(%left)
            set #summa2 %left [#k 6] * %imya [%left [#k 5] 2]
            set %left [#k 8] #summa2
        end_for
        sort_array %left 8 dec
        sort_array %left2 5 dec
        //save_array %left C:\Users\abc\Desktop\poiu1.txt
        // save_array %left2 C:\Users\abc\Desktop\poiu2.txt
        if  #zz > 0
            if  %left [1 8] < %left2 [1 9]
                log
                log : %left2 [1 1] %left2 [1 2]  %left2 [1 3] %left2 [1 4]      %left2 [1 5] %left2 [1 6]  %left2 [1 7] %left2 [1 8]    : %left2 [1 9]
                init_arr %xy (1) %left2 [1 1] %left2 [1 2] %left2 [1 3] %left2 [1 4]
            else
                log
                log : %left [1 2] %left [1 1]  %left [1 4] %left [1 3]      %left [1 6] %left [1 7]    : %left [1 8]
                init_arr %xy (1) %left [1 2] %left [1 1] %left [1 4] %left [1 3]
            end_if
        else
            log
            log : %left [1 2] %left [1 1]  %left [1 4] %left [1 3]      %left [1 6] %left [1 7]    : %left [1 8]
            init_arr %xy (1) %left [1 2] %left [1 1] %left [1 4] %left [1 3]
        end_if
    end_if
    set #x1 (#startX + %xy [1 2] * #stepX) - #stepX - %workwindow [1 1]
    set #y1 (#startY + %xy [1 1] * #stepY) - #stepY - %workwindow [1 2]
    set #x2 (#startX + %xy [1 4] * #stepX) - #stepX - %workwindow [1 1]
    set #y2 (#startY + %xy [1 3] * #stepY) - #stepY - %workwindow [1 2]
return

:square
    set #square findimage (%skill[1 1] %skill[1 2] %skill[1 3] %skill[1 4] (%kvadrat [1 1]) %squa)
    if  #square > 0
        log 
        left %squa [1 1] %squa [1 2]
        wait #waitskill + random(200)
        for #i 1 6
            for #j 1 6
                switch %a [#i #j]
                    case 1: set %sum [#i #j] 0
                        break
                    case 2: set %sum [#i #j] 5
                        break
                    case 3: set %sum [#i #j] 3
                        break
                    case 4: set %sum [#i #j] 1
                        break
                    case 5: set %sum [#i #j] 0
                end_switch
            end_for
        end_for
        set #z 0
        for #i 2 5
            for #j 2 5
                set #z #z + 1
                set #i_1 #i - 1
                set #i_2 #i + 1
                set #j_1 #j - 1
                set #j_2 #j + 1
                set %sum1 [#z] %sum[#i_1 #j_1] + %sum[#i_1 #j] + %sum[#i_1 #j_2] + %sum[#i #j_1] + %sum[#i #j] + %sum[#i #j_2] + %sum[#i_2 #j_1] + %sum[#i_2 #j] + %sum[#i_2 #j_2]
                init_arr %sum1 (#z 3 2) #j #i
            end_for
        end_for
        sort_array %sum1 dec
        set #squareX %LevVerh [1 1] + %workwindow [1 1] + #stepX * %sum1 [1 2] - #stepX
        set #squareY %LevVerh [1 2] + %workwindow [1 2] + #stepY * %sum1 [1 3] - #stepY
        left #squareX #squareY
        wait #waitskill + random(200)
    end_if
return

:krest
    set #krest findimage (%skill[1 1] %skill[1 2] %skill[1 3] %skill[1 4] (%krest [1 1]) %kres)
    if  #krest > 0
        log 
        left %kres [1 1] %kres [1 2]
        wait #waitskill  + random(200)
        for #i 1 6
            for #j 1 6
                switch %a [#i #j]
                    case 1: set %sum [#i #j] 0
                        break
                    case 2: set %sum [#i #j] 5
                        break
                    case 3: set %sum [#i #j] 3
                        break
                    case 4: set %sum [#i #j] 1
                        break
                    case 5: set %sum [#i #j] 0
                end_switch
            end_for
        end_for
        init_arr %x (1) -2 -1 0 1 2
        init_arr %y (1) -2 -1 1 2
        for #i 1 6
            for #j 1 6
                set #sumkrest 0
                for #k 1 size(%x [1])
                    set #tmpX #i + %x [1 #k]
                    if  #tmpX > 0 and #tmpX < 7
                        set #sumkrest #sumkrest + %sum [#j #tmpX]
                    end_if
                end_for
                for #l 1 size(%y [1])
                    set #tmpY #j + %y [1 #l]
                    if  #tmpY > 0 and #tmpY < 7
                        set #sumkrest #sumkrest + %sum [#tmpY #i]
                    end_if
                end_for
                set #zkrest #zkrest + 1
                init_arr %sum2 (#zkrest) #sumkrest #i #j
            end_for
        end_for
        sort_array %sum2 dec
        set #krestX %LevVerh [1 1] + %workwindow [1 1] + #stepX * %sum2 [1 2] - #stepX
        set #krestY %LevVerh [1 2] + %workwindow [1 2] + #stepY * %sum2 [1 3] - #stepY
        left #krestX #krestY
        wait #waitskill + random(200)
    end_if
return

:mp
    set size(%result1)
    set #timeproc1 timer + #timeproc
    while size(%result1) = 0 and (#timeproc1 > timer or #timeproc = 0)
        set #z 0
        set %get GetImage(#GetStartX #GetStartY #GetEndX #GetEndY)      //     
        for #i 1 size(%number)
            set #a Findimage(0 0 %get [1 2] %get [1 3] (%image[#i 1]) %mp %get [1 1] #accuracy -1 #deviation)   // 
            if  #a < 0
                log   .  : #a
                log  
                stop_script
            end_if
            if  #a > 0
                for #j 1 size(%mp)
                    set #z #z + 1
                    init_arr %result1 (1 1 #z) %number[#i] %mp[#j 1] %mp[#j 2]   //     
                end_for
            end_if
            wait #waitimage
        end_for
        if  size(%result1) > 0
            gosub sortY        //   Y  X
        end_if
        set $b DeleteImage(%get[1 1])    //  ,  GetImage
    end_while
return                 //   

:sortY
    set #z 0
    set #z1 0
    set #z2 1
    set #z4 0
    sort_array %result1 -3
    while 1 = 1
        set #z 0
        set size(%tmp)
        for #i #z2 eval(size(%result1 [1]) - 1)
            set #j #i + 1
            set #x %result1 [3 #i] - %result1 [3 #j]
            if  abs(#x) < #deltaY
                set #z #z + 1
                init_arr %tmp (1 1 #z) %result1 [1 #i]  %result1 [2 #i] %result1 [3 #i]
            else
                set #z #z + 1
                init_arr %tmp (1 1 #z) %result1 [1 #i]  %result1 [2 #i] %result1 [3 #i]
                break
            end_if
        end_for
        set #z2 #z2 + #z
        if  #z2 = size(%result1[])
            set #x %result1 [3 #i] - %result1 [3 #j]
            if  abs(#x) > #deltaY
                set #jj #j
                sort_array %tmp -2
                set #z1 #z1 + 1
                init_arr %result (#z1) %tmp [1]
                gosub space
                set size(%tmp)
                set #z #z + 1
                init_arr %tmp (1 1 #z) %result1 [1 #jj]  %result1 [2 #jj] %result1 [3 #jj]
                set #z1 #z1 + 1
                set %result [#z1] %tmp [1]
                gosub end
            end_if
            set #z #z + 1
            init_arr %tmp (1 1 #z) %result1 [1 #j]  %result1 [2 #j] %result1 [3 #j]
            sort_array %tmp -2
            set #z1 #z1 + 1
            init_arr %result (#z1) %tmp [1]
            gosub space
            break
        else
            sort_array %tmp -2
            set #z1 #z1 + 1
            init_arr %result (#z1) %tmp [1]
            gosub space
        end_if
    end_while
return

:space
    set #z3 0
    set size(%space)
    set #z4 #z4 + 1
    for #i 1 eval(size(%tmp[]) - 1)
        set #j #i + 1
        set #space  %tmp [2 #i] - %tmp [2 #j]
        if  abs(#space) > #deltaspace
            set #z3 #z3 + 1
            set %space[#z3] #j
        end_if
    end_for
    for #i 1 size(%space)
        set $str %result [#z4]
        set $str insert(" " $str %space[#i])
        set #j #i + 1
        set %space[#j] %space[#j] + #i
        set %result [#z4] $str
    end_for
    for #i 1 size(%result)
        set size(%tmp1)
        init_arr %tmp1 (1) %result [#i]
        for #j 1 size(%tmp1[1])
            set %result [#i #j] %tmp1 [1 #j]
        end_for
    end_for
return

:
    set #bers findimage (%skill[1 1] %skill[1 2] %skill[1 3] %skill[1 4] (%berserk [1 1]) %bers)
    if  #bers > 0
        log 
        left %bers [1 1] %bers [1 2]
        wait #waitskill + random(200)
    end_if
return

:
    set #thunder findimage (%skill[1 1] %skill[1 2] %skill[1 3] %skill[1 4] (%thunder [1 1]) %thun)
    if  #thunder > 0
        log 
        left %thun [1 1] %thun [1 2]
        wait #waitskill + random(200)
    end_if
return