Profile
- Name
- Cut And Wiggle Quick
- ID
- 49594
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- July 13, 2014 at 23:05 PM UTC
- Updated on
- July 13, 2014 at 23:05 PM UTC
- Description
Does a user-chosen number of C&W fuse runs with user-chosen stepsize. Works nicely with banders.
Best for
Code
-------------------------------------------------------------------------------
-- Cut And Wiggle Quick
--
-- Performs a fuse-wiggle with cuts inserted every "stepsize" spot
-- Randomly chooses shifts to attempt for a fixed number of tries.
--
-- Originally by Susume
-- Modifications by KarenCH
-------------------------------------------------------------------------------
StepSize=10
OffsetCount = 5
lowCI=0.3
highCI=1.0
shortwiggle = 8
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( "Cutting every "..StepSize.." segs for "..offsetCount.." attempts" )
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
end
print( "High score = "..highscore )
save.Quickload( 3 )
end
end
------------------------------------------------------------------------------------
-- USER DIALOG BOX
------------------------------------------------------------------------------------
function GetParams( )
dlg = dialog.CreateDialog( "Cut And Wiggle" )
dlg.step = dialog.AddSlider( "Stepsize", StepSize, 1, 20, 0 )
dlg.offct = dialog.AddSlider( "AttemptCount", OffsetCount, 1, 20, 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
OffsetCount = dlg.offct.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 )