Icon representing a recipe

Recipe: Cut And Wiggle Forever

created by KarenCH

Profile


Name
Cut And Wiggle Forever
ID
49595
Shared with
Public
Parent
None
Children
Created on
July 13, 2014 at 23:06 PM UTC
Updated on
July 13, 2014 at 23:06 PM UTC
Description

An evo script that runs lots of cut-and-wiggle actions with decreasing stepsize.

Best for


Code


------------------------------------------------------------------------------- -- Cut And Wiggle Forever -- -- Performs a fuse-wiggle with cuts inserted every "stepsize" spot -- Randomly chooses shifts to attempt for a fixed number of tries. -- Decrements stepsize if "enough" shifts have failed to produce gain. -- -- Originally by Susume -- Gui and features added by KarenCH ------------------------------------------------------------------------------- StepSize=10 OffsetCount = 1000000 -- an absurdly large value so we can ignore it FailThreshold = 5 lowCI=0.3 highCI=1.0 shortwiggle = 1 longwiggle = 25 EndSegment = structure.GetCount() ------------------------------------------------------------------------------------ -- HELPER FUNCTIONS AND INTERNAL-ONLY CONSTANTS ------------------------------------------------------------------------------------ OriginalCI = 1.0 function seedRandom() seed=os.time()/math.abs( current.GetEnergyScore() ) seed=seed%0.001 seed=1/seed while seed<10000000 do seed=seed*1000 end seed=seed-seed%1 print("Seed is: "..seed) math.randomseed(seed) end ------------------------------------------------------------------------------------ -- THE WIGGLER ------------------------------------------------------------------------------------ function DoWiggle( stepsize, offsetCount ) highscore=current.GetEnergyScore( ) print( "Starting score "..highscore ) print( "Cut every "..StepSize.." segs, decrease when "..FailThreshold.." attempts fail to gain" ) local failCount = 0 for i=1, offsetCount do offset = math.random( stepsize ) print( "Starting at seg "..offset.." with stepsize="..stepsize ) for i = offset, EndSegment-1, stepsize do structure.InsertCut( i ) end behavior.SetClashImportance( lowCI ) structure.WiggleAll( shortwiggle ) behavior.SetClashImportance( highCI) structure.WiggleAll( longwiggle ) for i = offset, EndSegment-1, stepsize do structure.DeleteCut( i ) end behavior.SetClashImportance( lowCI ) structure.WiggleAll( shortwiggle ) recentbest.Save( ) behavior.SetClashImportance( highCI ) structure.WiggleAll( longwiggle ) recentbest.Restore( ) newscore = current.GetEnergyScore( ) print( "New score = "..newscore ) if newscore > highscore then save.Quicksave( 3 ) highscore = newscore failCount = 0 else failCount = failCount + 1 end print( "High score = "..highscore ) save.Quickload( 3 ) if failCount > FailThreshold then if stepsize == 1 then break end stepsize = stepsize - 1 failCount = 0 end end end ------------------------------------------------------------------------------------ -- USER DIALOG BOX ------------------------------------------------------------------------------------ function GetParams( ) dlg = dialog.CreateDialog( "Cut And Wiggle" ) dlg.step = dialog.AddSlider( "InitialStepsize", StepSize, 1, 20, 0 ) dlg.fails = dialog.AddSlider( "FailsToDropStepsize", FailThreshold, 1, 50, 0 ) dlg.lowCI = dialog.AddSlider( "LowCI", lowCI, 0, 1, 2 ) dlg.highCI = dialog.AddSlider( "HighCI", highCI, 0, 1, 2 ) dlg.shortwiggle = dialog.AddSlider( "ShortWiggleIters", shortwiggle, 1, 10, 0 ) dlg.longwiggle = dialog.AddSlider( "LongWiggleIters", longwiggle, 1, 50, 0 ) dlg.ok = dialog.AddButton( "OK", 1 ) dlg.cancel = dialog.AddButton( "Cancel", 0 ) if dialog.Show( dlg ) > 0 then StepSize = dlg.step.value FailThreshold = dlg.fails.value lowCI = dlg.lowCI.value highCI = dlg.highCI.value shortwiggle = dlg.shortwiggle.value longwiggle = dlg.longwiggle.value return true else print( "dialog cancelled" ) return false end end ------------------------------------------------------------------------------------ -- CONTROLLERS: SETUP AND CLEANUP ------------------------------------------------------------------------------------ function cleanup( ) save.Quickload( 3 ) for i = 1, EndSegment-1 do structure.DeleteCut( i ) -- try not to leave cuts lying around! end behavior.SetClashImportance( OriginalCI ) end function main( ) seedRandom() print( "Original in slot 2, High score in slot 3" ) save.Quicksave( 2 ) --starting position save.Quicksave( 3 ) --high score OriginalCI = behavior.GetClashImportance( ) while GetParams( ) do DoWiggle( StepSize, OffsetCount ) end cleanup( ) end xpcall( main,cleanup )

Comments


KarenCH Lv 1

Yeah, it's not that well named in that regard.

If it isn't seeing any benefit, it decides to stop trying. Not sure if I should change anything or not…