Profile


Name
Band Melt 1.1
ID
100065
Shared with
Public
Parent
None
Children
Created on
October 12, 2014 at 18:41 PM UTC
Updated on
October 12, 2014 at 18:41 PM UTC
Description

Wiggle progressively melting the existing bands

Best for


Code


--Band Melt by Bruno Kestemont 8/10/2014 --With user bands, simple wiggle and changing band strength --v1.0.1 11/10/2014 --v1.1. added dialog recipename="Band Melt 1.1 by BK" --USER OPTIONS (to be used in dialog box) startMult=1 -- multiplier of starting point band strength mult=0.9 -- multiplier of band strength each loop PROBABLEFILTER=false restoreMult=1 MinStartMult=0.5 MaxStartMult=10 MinMult=0.1 MaxMult=2 MinrestoreMult=0 MaxrestoreMult=10 --SLOTS: bsslot=3 -- best score slot --INITS ubandlist= {} ubcount=band.GetCount() OriginalFilterSetting = behavior.GetSlowFiltersDisabled() function Score()--return score, exploration too if energy==true then return current.GetEnergyScore() else return current.GetScore() end end rss=Score() -- recipe starting score bestScore=rss --GENERIC FUNCTIONS function random(n1,n2) --random function returns int or float depends on input vars if n2==nil and n1==nil then return math.random() --float else if n2==nil then if n1%1==0 then return math.random(n1) --integer else return math.random()*n1 --float end else if n1%1==0 and n2%1==0 then return math.random(n1,n2) --integer between else return math.random()*(n2-n1)+n1 --float between end end end end function r4 ( i ) return i - i % 0.0001 end function r3 ( i ) return i - i % 0.001 end function r1 ( i ) return i - i % 0.1 end function r0 ( i ) -- cut all decimals return i - i % 1 end function CI(c) if c>maxCI then c=maxCI end behavior.SetClashImportance(c) end function Wiggle(how, iters, minppi) if PROBABLEFILTER then behavior.SetSlowFiltersDisabled(true) end-- new BK 8/4/2013, always disable filter here if how==nil then how="wa" end if iters==nil then iters=6 end if minppi==nil then minppi=0.1 end if iters>0 then iters=iters-1 sp=Score() if how == "s" then if PROBABLEFILTER then behavior.SetSlowFiltersDisabled(OriginalFilterSetting) end -- new BK 8/4/2013, always back to user settings if mutateAlwas==true then structure.MutateSidechainsSelected(1) else structure.ShakeSidechainsSelected(1) end elseif how == "wb" then structure.WiggleAll(2, true,false) elseif how == "ws" then structure.WiggleAll(2, false,true) elseif how == "wa" then structure.WiggleAll(2) end ep = Score() ig=ep-sp if how~="s" then if ig > minppi then return Wiggle(how, iters, minppi) end --tail call end end if PROBABLEFILTER then behavior.SetSlowFiltersDisabled(OriginalFilterSetting) end -- new BK 10/10/2013, always back to user settings end function SaveBest() local g=Score()-bestScore if g>0 then if g>0.01 then print("Gained another "..r3(g).." pts. Score: "..r3(Score()).. " from "..r3(rss)) end bestScore=Score() save.Quicksave(bsslot) end end --BAND MELT function uMakeBands() -- identify user bands for i=1, ubcount do ubandlist[i]=i end if #ubandlist==0 then USERBANDS=false else USERBANDS=true end return ubandlist end strengthtable={} -- global in order to jump over save.best maxstrength=0.1 PossibleRange=true function SetNewStrengths(bandtable) -- changing band strength for i= 1, #bandtable do if PossibleRange then band.SetStrength(i, strengthtable[i]) else band.SetStrength(i, 10) end end end function MakeStrengthTable(bandtable, multiplier) maxstrength=0.1 for i= 1, #bandtable do strengthtable[i]=r1(band.GetStrength(i)*multiplier) -- Warning, strength is rounded to 1-2 decimals max if strengthtable[i]>maxstrength then maxstrength=strengthtable[i] end end if maxstrength==0 then maxstrength=0.1 --because I think it stops at 0 elseif maxstrength>=10 then maxstrength=10 --because I think it stops at 10 --PossibleRange=false end print("Maximum band strength= ".. maxstrength) --return maxstrength -- to global end function SetDialogMultipliers() -- contextual setting of limits for dialog if maxstrength<=0.1 then --maxstrength=0.1 --startMult=1 -- multiplier of starting point band strength mult=1.6 -- multiplier of band strength each loop --restoreMult=1 --MinStartMult=1 --MaxStartMult=100 MinMult=1.6 MaxMult=5 --MinrestoreMult=1 --MaxrestoreMult=100 elseif maxstrength>=10 then --startMult=10/maxstrength -- multiplier of starting point band strength --maxstrength=10 mult=0.9 -- multiplier of band strength each loop --restoreMult=1 --MinStartMult=0.1 --MaxStartMult=1 MinMult=0.1 MaxMult=0.9 --MinrestoreMult=0.1 --MaxrestoreMult=1 elseif maxstrength>1 then --startMult=1 -- multiplier of starting point band strength --maxstrength=10 mult=0.9 -- multiplier of band strength each loop restoreMult=1 --MinStartMult=0.1 --MaxStartMult=10 MinMult=0.1 MaxMult=0.9 --MinrestoreMult=0.1 --MaxrestoreMult=1 else --startMult=1 -- multiplier of starting point band strength --maxstrength=0.1 mult=1+(1-maxstrength) -- multiplier of band strength each loop --restoreMult=1 --MinStartMult=0.9 --MaxStartMult=10/maxstrength MinMult=1 MaxMult=5 --MinrestoreMult=0.5 --MaxrestoreMult=10 end end function GetParameters () local dlog = dialog.CreateDialog ( recipename ) repeat dlog.label0=dialog.AddLabel("Current maximum band strength= "..maxstrength) --dlog.label1=dialog.AddLabel("Start with current band strengths multiplied by:") --dlog.startMult = dialog.AddSlider ( "Start Multiplier" , startMult , MinStartMult , MaxStartMult , 1 ) --dlog.label2=dialog.AddLabel("----------------------") dlog.label3=dialog.AddLabel("Each loop, multiply band strength by:") dlog.mult = dialog.AddSlider ( "Multiplier" , mult , MinMult, MaxMult , 1 ) --dlog.label4=dialog.AddLabel("I recommend 0.9-1.1, not 1.0") --dlog.label5=dialog.AddLabel("----------------------") --dlog.label6=dialog.AddLabel("At the end, restore best solution strength multiplied by:") --dlog.restoreMult = dialog.AddSlider ( "Restore Multiplier" , restoreMult , MinrestoreMult, MaxrestoreMult, 1 ) dlog.ok = dialog.AddButton ( "OK" , 1 ) dlog.cancel = dialog.AddButton ( "Cancel" , 0 ) dlog.advanced = dialog.AddCheckbox ( "Reset Starting Band Strength" , false ) --if ( dialog.Show ( dlog ) ==2 ) then ParameterAdvanced() end parametersdone=false dlogresult = dialog.Show ( dlog ) if dlogresult > 0 then --startMult= dlog.startMult.value mult= dlog.mult.value if mult==1 then mult=0.99 print ("changing useless multiplier 1 to 0.99") end advanced=dlog.advanced.value -- to run advanced dialog if advanced then ParameterAdvanced() parametersdone= true --restoreMult = dlog.restoreMult.value if dlogresult==1 then dlogresult=4 end --to force return to main menu with new options end end until dlogresult<2 -- do not end if result is 4 return dlogresult> 0 -- returns true if we did ok somewhere, false if cancelled end function ParameterAdvanced() local dlog = dialog.CreateDialog ("Advanced parameters") --repeat dlog.label0=dialog.AddLabel("Current maximum band strength="..maxstrength) --dlog.label1=dialog.AddLabel("Start with current band strengths multiplied by:") --dlog.startMult = dialog.AddSlider ( "Start Multiplier" , startMult , MinStartMult , MaxStartMult , 1 ) dlog.label2=dialog.AddLabel("Upgrade all strengths, maximum being:") dlog.startMaxStrength = dialog.AddSlider ( "Set Max Strength" , maxstrength , 0.1 , 10 , 1 ) dlog.label3=dialog.AddLabel("WARNING: don't go away after clicking OK:") dlog.label4=dialog.AddLabel("I need some time to set the bands before next dialog") dlog.ok = dialog.AddButton ( "OK" , 1 ) --dlog.cancel = dialog.AddButton ( "Cancel" , 0 ) -- will cancel everything dlogresult=dialog.Show ( dlog ) -- global startMaxStrength=dlog.startMaxStrength.value startMult= startMaxStrength/maxstrength --startMult= dlog.startMult.value if dlogresult > 0 then -- global if math.abs(startMaxStrength-maxstrength)>0.1 then print("Setting start strengths using multiplier "..startMult) MakeStrengthTable(ubandlist, startMult) -- getting desired start strengths SetDialogMultipliers() -- depending on new maxstrength SetNewStrengths(ubandlist) end end --until dialog.Show ( dlog ) > 0 return dlogresult end function MAIN() print(recipename) print("Starting score = "..r3(rss)) if ubcount==0 then print("No band found ! Stopping recipe") return end local eg=0 -- end gain save.Quicksave(bsslot) -- init uMakeBands() MakeStrengthTable(ubandlist, 1) -- init getting current strengths SetDialogMultipliers() -- depending on current maxstrength if GetParameters () then print("Multiplier each loop = "..mult) repeat Wiggle() SaveBest() eg=Score()-rss --if eg>0.1 then print(">>Total gain= "..r3(eg).." Score: "..r3(Score())) end save.Quickload(bsslot) SetNewStrengths(ubandlist) -- temporary (will be used next loop) MakeStrengthTable(ubandlist, mult) -- global (will be used 1 loop after next loop) until maxstrength<=0.1 or maxstrength>=10 save.Quickload(bsslot) if eg<0 then eg=0 end print(">>Total gain= "..r3(eg).." Score: "..r3(Score())) maxstrength=MakeStrengthTable(ubandlist, restoreMult) -- in order to print resulting max strength --SetNewStrengths(ubandlist) end end MAIN()

Comments


Bruno Kestemont Lv 1

Can be used on Contact puzzles or quest to the native puzzles in order to stabilize the structure you want to give with bands.