Добавлен , опубликован
хотел сделать судоку на фреймах, но вышло как всегда говно, я попросту не смог разобраться в правильном алгоритме для его создания, мне казалось что у меня всё норм с ним, но потом понял что даун и лучше бы повесился
играть можно само собой, но не факт что оно сгенерирует правильное судоку и не факт, что у вас не зависнет при создании)
продолжительность ожидания может быть рандомной, но чем выше сложность, тем дольше ждать нужно (если повезёт, то ждать не нужно), вплоть до полторы минуты (если время было дольше, я просто перепускал карту)

InitFrames
library InitFramesLib requires MemoryHackFrameAPI
globals
    constant hashtable H = InitHashtable( )
    constant key ButtonTypeKey
    constant key ButtonIntegerKey
    constant key ButtonBooleanEditKey
    constant real Size = 0.25 // розмір сітки судоку
    constant real SizeInc = 0.03 // розмір при наведенні
    
    integer FrameGlobalId = -1
    
    integer array MainBackdropZones
    integer MainBackdropBorders
    integer MainBackdrop
    integer array Cell
    integer array CellButton
    integer array CellNumber
    
    integer InteractionMainBackdrop
    integer array InteractionCell
    integer array InteractionCellButton
    integer array InteractionCellNumber
    
    integer TextTime = 0
    integer TextDifficult = 0
    integer TextFault = 0
    integer FaultCount = 0
    
    integer bj_lastTrackedFrame = 0
    integer bj_lastClickedFrame = 0
    
    integer TempIntForClick = -1
    integer TempIntForClick_1 = 0
    
    boolean LMBTap = true
endglobals

function CreateFFrame takes string baseframe, integer parent returns integer
    set FrameGlobalId = FrameGlobalId + 1
    return CreateFrame( baseframe, parent, FrameGlobalId )
endfunction

private function Check takes nothing returns nothing
    local integer frame = FindCLayerUnderCursor( )
    
    if IsKeyPressed( 0x01 ) then // лкм
        if LMBTap then
            set LMBTap = false
            
            set bj_lastClickedFrame = frame
        endif
    else
        set LMBTap = true
        
        if bj_lastClickedFrame != 0 then
            if TempIntForClick != -1 and LoadInteger( H, frame, ButtonTypeKey ) != 2 and LoadInteger( H, frame, ButtonTypeKey ) != 3 then
                call SetFrameTexture( Cell[ TempIntForClick ], "UI\\Widgets\\Console\\Human\\CommandButton\\human-multipleselection-border.blp", false )
                set TempIntForClick = -1
            endif
            
            if LoadInteger( H, frame, ButtonTypeKey ) == 1 then // клік
                set TempIntForClick = LoadInteger( H, frame, ButtonIntegerKey )
                call SetFrameTexture( Cell[ TempIntForClick ], "UI\\Widgets\\Console\\Human\\CommandButton\\human-activebutton.blp", false )
            elseif TempIntForClick != -1 then
                if LoadBoolean( H, CellButton[ TempIntForClick ], ButtonBooleanEditKey ) != true then // цифру можна змінити (не біла)
                    if LoadInteger( H, frame, ButtonTypeKey ) == 2 then // була нажата цифра зміни
                        if LoadInteger( H, TempIntForClick, SolvedCellKey ) == LoadInteger( H, frame, ButtonIntegerKey ) + 1 then // цифра вірна
                            set CellNumberSudoku[ TempIntForClick ] = LoadInteger( H, frame, ButtonIntegerKey ) + 1
                            call SetFrameText( CellNumber[ TempIntForClick ], "|c009bc8ff" + I2S( LoadInteger( H, frame, ButtonIntegerKey ) + 1 ) + "|r" )
                        else // невірна
                            set CellNumberSudoku[ TempIntForClick ] = LoadInteger( H, frame, ButtonIntegerKey ) + 1
                            call isSafe( Int2Row( TempIntForClick ), Int2Col( TempIntForClick ), CellNumberSudoku[ TempIntForClick ] )
                            call SetFrameText( CellNumber[ TempIntForClick ], "|c00ff3737" + I2S( CellNumberSudoku[ TempIntForClick ] ) + "|r" )
                            
                            set FaultCount = FaultCount + 1
                            call SetFrameText( TextFault, "Помилок: |c00ff3737" + I2S( FaultCount ) + "|r" )
                        endif
                    elseif LoadInteger( H, frame, ButtonTypeKey ) == 3 then // була нажата кнопка "очистити"
                        set CellNumberSudoku[ TempIntForClick ] = 0
                        call SetFrameText( CellNumber[ TempIntForClick ], "" )
                    endif
                endif
            endif
            
            set bj_lastClickedFrame = 0
        endif
    endif
    
    if frame != bj_lastTrackedFrame then // наведення мишкою
        if bj_lastTrackedFrame != 0 then
            if LoadInteger( H, bj_lastTrackedFrame, ButtonTypeKey ) == 1 then
                call SetFrameSize( Cell[ LoadInteger( H, bj_lastTrackedFrame, ButtonIntegerKey ) ], Size / 9.00, Size / 9.00 )
            elseif LoadInteger( H, bj_lastTrackedFrame, ButtonTypeKey ) == 2 then
                call SetFrameSize( InteractionCell[ LoadInteger( H, bj_lastTrackedFrame, ButtonIntegerKey ) ], Size / 9.00, Size / 9.00 )
            elseif LoadInteger( H, bj_lastTrackedFrame, ButtonTypeKey ) == 3 then
                call SetFrameSize( InteractionCell[ LoadInteger( H, bj_lastTrackedFrame, ButtonIntegerKey ) ], Size / 3.00, Size / 9.00 )
            endif
            
            if LoadInteger( H, frame, ButtonTypeKey ) == 1 then
                call SetFrameSize( Cell[ LoadInteger( H, frame, ButtonIntegerKey ) ], SizeInc, SizeInc )
            elseif LoadInteger( H, frame, ButtonTypeKey ) == 2 then
                call SetFrameSize( InteractionCell[ LoadInteger( H, frame, ButtonIntegerKey ) ], SizeInc, SizeInc )
            elseif LoadInteger( H, frame, ButtonTypeKey ) == 3 then
                call SetFrameSize( InteractionCell[ LoadInteger( H, frame, ButtonIntegerKey ) ], Size / 3.00 + 0.005, SizeInc )
            endif
        endif
        
        set bj_lastTrackedFrame = frame
    endif
endfunction

function InitFrames_Actions takes nothing returns nothing
    local integer i = 0
    local integer i1
    local real x = 0.00
    local real y = 0.00
    local real size = Size
    
    call EnableOPLimit( false )
    call TriggerSleepAction( 0.00 )
    call LoadTOCFile( "FramesTOC.toc" )
    
    set MainBackdrop = CreateFFrame( "Backdrop", pGameUI )
    call SetFrameAbsolutePoint( MainBackdrop, ANCHOR_CENTER, 0.40, 0.35 )
    call SetFrameSize( MainBackdrop, size, size )
    call SetFrameTexture( MainBackdrop, "empty.blp", false )
    
    set size = size / 3.00
    
    set MainBackdropZones[0] = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( MainBackdropZones[0], ANCHOR_TOPLEFT, MainBackdrop, ANCHOR_TOPLEFT, 0.00, 0.00 )
    call SetFrameSize( MainBackdropZones[0], size, size )
    call SetFrameTexture( MainBackdropZones[0], "UI\\Widgets\\EscMenu\\NightElf\\nightelf-options-menu-background.blp", false )
    
    set MainBackdropZones[1] = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( MainBackdropZones[1], ANCHOR_TOPRIGHT, MainBackdrop, ANCHOR_TOPRIGHT, 0.00, 0.00 )
    call SetFrameSize( MainBackdropZones[1], size, size )
    call SetFrameTexture( MainBackdropZones[1], "UI\\Widgets\\EscMenu\\NightElf\\nightelf-options-menu-background.blp", false )
    
    set MainBackdropZones[2] = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( MainBackdropZones[2], ANCHOR_CENTER, MainBackdrop, ANCHOR_CENTER, 0.00, 0.00 )
    call SetFrameSize( MainBackdropZones[2], size, size )
    call SetFrameTexture( MainBackdropZones[2], "UI\\Widgets\\EscMenu\\NightElf\\nightelf-options-menu-background.blp", false )
    
    set MainBackdropZones[3] = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( MainBackdropZones[3], ANCHOR_BOTTOMLEFT, MainBackdrop, ANCHOR_BOTTOMLEFT, 0.00, 0.00 )
    call SetFrameSize( MainBackdropZones[3], size, size )
    call SetFrameTexture( MainBackdropZones[3], "UI\\Widgets\\EscMenu\\NightElf\\nightelf-options-menu-background.blp", false )
    
    set MainBackdropZones[4] = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( MainBackdropZones[4], ANCHOR_BOTTOMRIGHT, MainBackdrop, ANCHOR_BOTTOMRIGHT, 0.00, 0.00 )
    call SetFrameSize( MainBackdropZones[4], size, size )
    call SetFrameTexture( MainBackdropZones[4], "UI\\Widgets\\EscMenu\\NightElf\\nightelf-options-menu-background.blp", false )
    
    set MainBackdropZones[5] = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( MainBackdropZones[5], ANCHOR_TOP, MainBackdrop, ANCHOR_TOP, 0.00, 0.00 )
    call SetFrameSize( MainBackdropZones[5], size, size )
    call SetFrameTexture( MainBackdropZones[5], "UI\\Widgets\\EscMenu\\Human\\quest-normal-background.blp", false )
    
    set MainBackdropZones[6] = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( MainBackdropZones[6], ANCHOR_LEFT, MainBackdrop, ANCHOR_LEFT, 0.00, 0.00 )
    call SetFrameSize( MainBackdropZones[6], size, size )
    call SetFrameTexture( MainBackdropZones[6], "UI\\Widgets\\EscMenu\\Human\\quest-normal-background.blp", false )
    
    set MainBackdropZones[7] = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( MainBackdropZones[7], ANCHOR_RIGHT, MainBackdrop, ANCHOR_RIGHT, 0.00, 0.00 )
    call SetFrameSize( MainBackdropZones[7], size, size )
    call SetFrameTexture( MainBackdropZones[7], "UI\\Widgets\\EscMenu\\Human\\quest-normal-background.blp", false )
    
    set MainBackdropZones[8] = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( MainBackdropZones[8], ANCHOR_BOTTOM, MainBackdrop, ANCHOR_BOTTOM, 0.00, 0.00 )
    call SetFrameSize( MainBackdropZones[8], size, size )
    call SetFrameTexture( MainBackdropZones[8], "UI\\Widgets\\EscMenu\\Human\\quest-normal-background.blp", false )
    
    set size = size / 3.00
    
    loop
        set i1 = 0
        set x  = 0.00
        
        loop
            set Cell[i * 9 + i1] = CreateFFrame( "Backdrop", MainBackdrop )
            
            call SetFramePoint( Cell[i * 9 + i1], ANCHOR_TOPLEFT, MainBackdrop, ANCHOR_TOPLEFT, x, y )
            call SetFrameSize( Cell[i * 9 + i1], size, size )
            call SetFrameTexture( Cell[i * 9 + i1], "UI\\Widgets\\Console\\Human\\CommandButton\\human-multipleselection-border.blp", false )
            
            set CellButton[i * 9 + i1] = CreateFFrame( "Button", Cell[i * 9 + i1] )
            call SetFramePoint( CellButton[i * 9 + i1], ANCHOR_TOPLEFT, Cell[i * 9 + i1], ANCHOR_TOPLEFT, 0.00, 0.00 )
            call SetFramePoint( CellButton[i * 9 + i1], ANCHOR_BOTTOMRIGHT, Cell[i * 9 + i1], ANCHOR_BOTTOMRIGHT, 0.00, 0.00 )
            call SaveInteger( H, CellButton[i * 9 + i1], ButtonTypeKey, 1 )
            call SaveInteger( H, CellButton[i * 9 + i1], ButtonIntegerKey, i * 9 + i1 )
            
            set CellNumber[i * 9 + i1] = CreateFFrame( "Text", Cell[i * 9 + i1] )
            call SetFramePoint( CellNumber[i * 9 + i1], ANCHOR_CENTER, Cell[i * 9 + i1], ANCHOR_CENTER, 0.00, 0.00 )
            call SetFrameFont( CellNumber[i * 9 + i1], "Fonts\\FRIZQT__.TTF", 0.018, 0 )
            call DisableFrame( CellNumber[i * 9 + i1] )
            
            set i1 = i1 + 1
            exitwhen i1 > 8
            set x = x + size
        endloop
        
        set i = i + 1
        exitwhen i > 8
        set y = y - size
    endloop
    
    //==============
    set InteractionMainBackdrop = CreateFFrame( "Backdrop", MainBackdrop )
    call SetFramePoint( InteractionMainBackdrop, ANCHOR_BOTTOMLEFT, MainBackdrop, ANCHOR_BOTTOMRIGHT, 0.01, size )
    call SetFrameSize( InteractionMainBackdrop, size * 3.00, size * 3.00 )
    call SetFrameTexture( InteractionMainBackdrop, "empty.blp", false )
    
    set i = 0
    set y = 0.00
    loop
        set i1 = 0
        set x  = 0.00
        
        loop
            set InteractionCell[i * 3 + i1] = CreateFFrame( "Backdrop", InteractionMainBackdrop )
            
            call SetFramePoint( InteractionCell[i * 3 + i1], ANCHOR_TOPLEFT, InteractionMainBackdrop, ANCHOR_TOPLEFT, x, y )
            call SetFrameSize( InteractionCell[i * 3 + i1], size, size )
            call SetFrameTexture( InteractionCell[i * 3 + i1], "UI\\Console\\Human\\human-transport-slot.blp", false )
            
            set InteractionCellButton[i * 3 + i1] = CreateFFrame( "Button", InteractionCell[i * 3 + i1] )
            call SetFramePoint( InteractionCellButton[i * 3 + i1], ANCHOR_TOPLEFT, InteractionCell[i * 3 + i1], ANCHOR_TOPLEFT, 0.00, 0.00 )
            call SetFramePoint( InteractionCellButton[i * 3 + i1], ANCHOR_BOTTOMRIGHT, InteractionCell[i * 3 + i1], ANCHOR_BOTTOMRIGHT, 0.00, 0.00 )
            call SaveInteger( H, InteractionCellButton[i * 3 + i1], ButtonTypeKey, 2 )
            call SaveInteger( H, InteractionCellButton[i * 3 + i1], ButtonIntegerKey, i * 3 + i1 )
            
            set InteractionCellNumber[i * 3 + i1] = CreateFFrame( "Text", InteractionCell[i * 3 + i1] )
            call SetFramePoint( InteractionCellNumber[i * 3 + i1], ANCHOR_CENTER, InteractionCell[i * 3 + i1], ANCHOR_CENTER, 0.00, 0.00 )
            call SetFrameFont( InteractionCellNumber[i * 3 + i1], "Fonts\\FRIZQT__.TTF", 0.02, 0 )
            call SetFrameText( InteractionCellNumber[i * 3 + i1], I2S( i * 3 + i1 + 1 ) )
            call DisableFrame( InteractionCellNumber[i * 3 + i1] )
            
            set i1 = i1 + 1
            exitwhen i1 >= 3
            set x = x + size
        endloop
        
        set i = i + 1
        exitwhen i >= 3
        set y = y - size
    endloop
    
    set InteractionCell[9] = CreateFFrame( "Backdrop", InteractionMainBackdrop )
            
    call SetFramePoint( InteractionCell[9], ANCHOR_TOP, InteractionMainBackdrop, ANCHOR_BOTTOM, 0.00, 0.00 )
    call SetFrameSize( InteractionCell[9], size * 3.00, size )
    call SetFrameTexture( InteractionCell[9], "UI\\Console\\Human\\human-transport-slot.blp", false )
            
    set InteractionCellButton[9] = CreateFFrame( "Button", InteractionCell[9] )
    call SetFramePoint( InteractionCellButton[9], ANCHOR_TOPLEFT, InteractionCell[9], ANCHOR_TOPLEFT, 0.00, 0.00 )
    call SetFramePoint( InteractionCellButton[9], ANCHOR_BOTTOMRIGHT, InteractionCell[9], ANCHOR_BOTTOMRIGHT, 0.00, 0.00 )
    call SaveInteger( H, InteractionCellButton[9], ButtonTypeKey, 3 )
    call SaveInteger( H, InteractionCellButton[9], ButtonIntegerKey, 9 )
            
    set InteractionCellNumber[9] = CreateFFrame( "Text", InteractionCell[9] )
    call SetFramePoint( InteractionCellNumber[9], ANCHOR_CENTER, InteractionCell[9], ANCHOR_CENTER, 0.00, 0.00 )
    call SetFrameFont( InteractionCellNumber[9], "Fonts\\FRIZQT__.TTF", 0.0135, 0 )
    call SetFrameText( InteractionCellNumber[9], "очистити" )
    call DisableFrame( InteractionCellNumber[9] )
    
    set TextDifficult = CreateFFrame( "Text", MainBackdrop )
    call SetFramePoint( TextDifficult, ANCHOR_BOTTOMLEFT, MainBackdrop, ANCHOR_TOPLEFT, 0.00, 0.03 )
    call SetFrameFont( TextDifficult, "Fonts\\FRIZQT__.TTF", 0.015, 0 )
    
    set TextFault = CreateFFrame( "Text", MainBackdrop )
    call SetFramePoint( TextFault, ANCHOR_BOTTOMLEFT, MainBackdrop, ANCHOR_TOPLEFT, 0.00, 0.015 )
    call SetFrameFont( TextFault, "Fonts\\FRIZQT__.TTF", 0.015, 0 )
    call SetFrameText( TextFault, "Помилок: 0" )
    
    set TextTime = CreateFFrame( "Text", MainBackdrop )
    call SetFramePoint( TextTime, ANCHOR_BOTTOMLEFT, MainBackdrop, ANCHOR_TOPLEFT, 0.00, 0.00 )
    call SetFrameFont( TextTime, "Fonts\\FRIZQT__.TTF", 0.015, 0 )
    call SetFrameText( TextTime, "Час: 00:00:00" )
    
    call TriggerExecute( gg_trg_Sudoku )
    call TimerStart( CreateTimer( ), 0.01, true, function Check )
endfunction
endlibrary

//===========================================================================
function InitTrig_InitFrames takes nothing returns nothing
    set gg_trg_InitFrames = CreateTrigger(  )
    call TriggerAddAction( gg_trg_InitFrames, function InitFrames_Actions )
endfunction

Sudoku
library SudokuLib
globals
    constant key SolvedCellKey
    constant key SolvedCellKey_2
    
    constant integer MODE_EASY   = 0
    constant integer MODE_MEDIUM = 1
    constant integer MODE_HARD   = 2
    
    integer array CellNumberSudoku
    
    boolean SolveSudokuBoolean = true
endglobals

function print takes nothing returns nothing
    local integer i = 0
    local integer j = 0
    
    loop
        loop
            if not HaveSavedBoolean( H, i * 9 + j, SolvedCellKey_2 ) then
                if CellNumberSudoku[i * 9 + j] > 0 then
                    call SetFrameText( CellNumber[i * 9 + j], I2S( CellNumberSudoku[i * 9 + j] ) )
                    call SaveBoolean( H, CellButton[i * 9 + j], ButtonBooleanEditKey, true )
                endif
            else
                set CellNumberSudoku[i * 9 + j] = 0
            endif
            
            
            set j = j + 1
            exitwhen j > 8
        endloop
        
        set i = i + 1
        exitwhen i > 8
        set j = 0
    endloop
endfunction

function Int2Col takes integer i returns integer
    local integer x = 0
    local integer y = 0
    
    loop
        loop
            if y * 9 + x == i then
                return x
            endif
            
            set x = x + 1
            exitwhen x > 8
        endloop
        
        set y = y + 1
        exitwhen y > 8
        set x = 0
    endloop
    
    return 0
endfunction

function Int2Row takes integer i returns integer
    local integer x = 0
    local integer y = 0
    
    loop
        loop
            if y * 9 + x == i then
                return y
            endif
            
            set x = x + 1
            exitwhen x > 8
        endloop
        
        set y = y + 1
        exitwhen y > 8
        set x = 0
    endloop
    
    return 0
endfunction

function isSafe takes integer row, integer col, integer num returns boolean
    local integer x = 0
    local integer i = 0
    local integer j = 0
    local integer startRow
    local integer startCol
    
    // Check if we find the same num
    // in the similar row , we
    // return false
    loop
        if CellNumberSudoku[ row * 9 + x ] == num then
            //call DisplayTimedTextToPlayer( GetLocalPlayer( ), 0.00, 0.00, 5.00, "така цифра вже є у ряду" )
            return false
        endif
        
        set x = x + 1
        exitwhen x > 8
    endloop
     
    // Check if we find the same num in
    // the similar column , we
    // return false
    set x = 0
    loop
        if CellNumberSudoku[ x * 9 + col ] == num then
            //call DisplayTimedTextToPlayer( GetLocalPlayer( ), 0.00, 0.00, 5.00, "така цифра вже є у стовбику" )
            return false
        endif
        
        set x = x + 1
        exitwhen x > 8
    endloop
 
    // Check if we find the same num in
    // the particular 3*3 matrix,
    // we return false
    
    if row > 5 then
        set startRow = 6
    elseif row > 2 then
        set startRow = 3
    else
        set startRow = 0
    endif
    
    if col > 5 then
        set startCol = 6
    elseif col > 2 then
        set startCol = 3
    else
        set startCol = 0
    endif
    
    loop
        // Check if it is safe to place
        // the num (1-9)  in the
        // given row ,col  ->we
        // move to next column
        loop
            if CellNumberSudoku[ ( i + startRow ) * 9 + ( j + startCol ) ] == num then
                //call DisplayTimedTextToPlayer( GetLocalPlayer( ), 0.00, 0.00, 5.00, "така цифра вже є у квадраті" )
                return false
            endif
            
            set j = j + 1
            exitwhen j >= 3
        endloop
        
        set i = i + 1
        exitwhen i >= 3
        set j = 0
    endloop
 
    return true
endfunction

function solveSudoku takes integer row, integer col returns boolean
    local integer num = 1
    
    // Check if we have reached the 8th
    // row and 9th column (0
    // indexed matrix) , we are
    // returning true to avoid
    // further backtracking
    if row == 8 and col == 9 then
        return true
    endif
 
    // Check if column value  becomes 9 ,
    // we move to next row and
    //  column start from 0
    if col == 9 then
        set row = row + 1
        set col = 0
    endif
   
    // Check if the current position of
    // the grid already contains
    // value >0, we iterate for next column
    if CellNumberSudoku[ row * 9 + col ] > 0 then
        return solveSudoku( row, col + 1 )
    endif
 
    loop
        if isSafe( row, col, num ) then
            //Assigning the num in
              //the current (row,col)
              //position of the grid
              //and assuming our assigned
              //num in the position
              //is correct     
            set CellNumberSudoku[ row * 9 + col ] = num
            //  Checking for next possibility with next
            //  column
            
            if solveSudoku( row, col + 1 ) then
                return true
            endif
        endif
        // Removing the assigned num ,
        // since our assumption
        // was wrong , and we go for
        // next assumption with
        // diff num value
        set CellNumberSudoku[ row * 9 + col ] = 0
        
        set num = num + 1
        exitwhen num > 9
    endloop
    
    return false
endfunction

function SudokuCreate takes integer mode returns nothing
    local integer x = 0
    local integer y = 0
    local integer j = 0
    local integer i = 0
    local integer c = 0
    local integer k = 0
    
    if mode == MODE_EASY then
        set k = GetRandomInt( 35, 40 )
        call SetFrameText( TextDifficult, "Складність: |c0000ff00легка|r" )
    elseif mode == MODE_MEDIUM then
        set k = GetRandomInt( 29, 31 )
        call SetFrameText( TextDifficult, "Складність: |c00ffff00середня|r" )
    else
        set k = GetRandomInt( 22, 24 )
        call SetFrameText( TextDifficult, "Складність: |c00ff9900тяжка|r" )
    endif
    
    loop
        set y = 0
        
        loop
            set x = 0
            
            loop
                loop
                    set c = GetRandomIntMem( 1, 9, 0 )
                    
                    exitwhen isSafe( y + i, x + i, c )
                endloop
                
                set CellNumberSudoku[ ( y + i ) * 9 + ( x + i ) ] = c
                
                set x = x + 1
                exitwhen x >= 3
            endloop
            
            set y = y + 1
            exitwhen y >= 3
        endloop
        
        set i = i + 3
        exitwhen i > 6
    endloop
    
    call solveSudoku( 0, 3 )
    
    set i = 0
    
    loop
        call SaveInteger( H, i, SolvedCellKey, CellNumberSudoku[ i ] )
        
        set i = i + 1
        exitwhen i > 80
    endloop
    
    set i = 0
    
    loop
        loop
            set x = GetRandomIntMem( 0, 80, 1 )
            set c = CellNumberSudoku[ x ]
            set y = 0
            
            loop
                if HaveSavedBoolean( H, y, SolvedCellKey_2 ) then
                    set CellNumberSudoku[ y ] = 0
                endif
                
                set y = y + 1
                exitwhen y > 80
            endloop
            
            set CellNumberSudoku[ x ] = 0
            
            if solveSudoku( 0, 0 ) then
                call SaveBoolean( H, x, SolvedCellKey_2, true )
                exitwhen true
            endif
        endloop
        
        set i = i + 1
        exitwhen i > 80 - k
    endloop
    
    call print( )
endfunction

globals
    integer seconds = 0
    integer minutes = 0
    integer hours = 0
endglobals

function CheckTime takes nothing returns nothing
    local string s = ""
    
    set seconds = seconds + 1
    
    if seconds >= 60 then
        set seconds = 0
        set minutes = minutes + 1
        
        if minutes >= 60 then
            set minutes = 0
            set hours = hours + 1
        endif
    endif
    
    if hours <= 9 then
        set s = s + "0"
    endif
    
    set s = s + I2S( hours ) + ":"
    
    if minutes <= 9 then
        set s = s + "0"
    endif
    
    set s = s + I2S( minutes ) + ":"
    
    if seconds <= 9 then
        set s = s + "0"
    endif
    
    set s = s + I2S( seconds )
    
    call SetFrameText( TextTime, "Час: " + s )
endfunction

function Sudoku_Actions takes nothing returns nothing
    call SudokuCreate( MODE_EASY ) //MODE_MEDIUM, MODE_HARD
    
    call TimerStart( CreateTimer( ), 1.00, true, function CheckTime )
endfunction
endlibrary

//===========================================================================
function InitTrig_Sudoku takes nothing returns nothing
    set gg_trg_Sudoku = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Sudoku, function Sudoku_Actions )
endfunction

RandomInt
library RandomIntGenMem
globals
    private constant hashtable H = InitHashtable( )
endglobals

function ClearRandomIntMem takes integer RandomIntKey returns nothing
    call FlushChildHashtable( H, RandomIntKey )
endfunction

function GetRandomIntMem takes integer lowBound, integer highBound, integer RandomIntKey returns integer
    local integer r
    local integer simple
    
    if highBound <= lowBound then
        return highBound
    endif
    
    set simple = GetRandomInt( lowBound, highBound )
    set r = simple
    
    loop
        exitwhen not HaveSavedBoolean( H, RandomIntKey, r )
        
        if r < highBound and r >= simple then
            set r = r + 1
        elseif r == highBound and simple > lowBound then
            set r = simple - 1
        elseif r > lowBound and r < simple then
            set r = r - 1
        elseif r <= lowBound or r >= highBound then
            set r = simple
            exitwhen true
        endif
    endloop
    
    if HaveSavedBoolean( H, RandomIntKey, r ) then
        call FlushChildHashtable( H, RandomIntKey )
    endif
    
    call SaveBoolean( H, RandomIntKey, r, true )
    
    return r
endfunction
endlibrary

//===========================================================================
//function InitTrig_RandomInt takes nothing returns nothing
  //  set gg_trg_RandomInt = CreateTrigger(  )
//endfunction


`
ОЖИДАНИЕ РЕКЛАМЫ...

Показан только небольшой набор комментариев вокруг указанного. Перейти к актуальным.
0
27
1 год назад
0
poisoNDealer, конечно, даже 2д танчики какие-нибудь_)
2
27
1 год назад
Отредактирован MpW
2
Норм. Попроси реьят помочь с алгоритмами. И можно это всунуть в мини игры в качестве рандома на арене. В принципе идея интересна

В интернете полно информации. Набери судоку алгоритм генерации

Жто не навоз. Норм переименуй
0
27
1 год назад
0
МрачныйВорон, это навоз, такое говно только я могу высрать)
я и искал алгоритм, это можно по комментариям в коде видеть)
вот основные ссылки которыми я пользовался
2
32
1 год назад
2
Загруженные файлы
2
9
1 год назад
Отредактирован Градоначальник
2
Крестики-нолики для 2 игроков была бы топ карта.
2
12
1 год назад
2
Мог бы сделать игру 2048 на фреймах, было бы даже проще. Можно будет использовать как мини игу в ТДшках, чтоб не помереть от скуки.
Показан только небольшой набор комментариев вокруг указанного. Перейти к актуальным.
Чтобы оставить комментарий, пожалуйста, войдите на сайт.