Icon representing a recipe

Recipe: Work bands.

created by MurloW

Profile


Name
Work bands.
ID
101394
Shared with
Public
Parent
None
Children
None
Created on
September 17, 2015 at 21:27 PM UTC
Updated on
September 17, 2015 at 21:27 PM UTC
Description

Randomly disables/enables bands to quake.

Best for


Code


-- Work bands -- MurloW function score() return current.GetScore() end function setCI(ci) return behavior.SetClashImportance(ci) end function cut(x) return x-x%0.0001 end nSegs=structure.GetCount() p=print function wig(how, it, iters, minppi) if DisFil then behavior.SetSlowFiltersDisabled(true) end if how==nil then how="wa" end if minppi==nil then minppi=2 end if iters==nil then iters=2 end if it==nil then it=10*ItMu end it=math.ceil(it) if iters>0 then iters=iters-1 local sp=score() if how == "s" then structure.ShakeSidechainsAll(1) elseif how == "wb" then structure.WiggleAll(it,true,false) elseif how == "ws" then structure.WiggleAll(it,false,true) elseif how == "wa" then structure.WiggleAll(it) end if score()-sp > minppi and how ~= "s" then return wig(how, it, iters, minppi) end end if DisFil then behavior.SetSlowFiltersDisabled(false) end end function Check() if (bestscore < score()) then gain = score() - bestscore bestscore = score() save.Quicksave(1) if gain>=0.002 then p(" ",cut(gain),"pts.") end else gain = 0 end end function Seed() -- Rav3n_pl seed=os.time()/math.abs(current.GetEnergyScore()) seed=seed%0.001 seed=1/seed while seed<10000000 do seed=seed*10 end seed=seed-seed%1 math.randomseed(seed) end Seed() function End(errmsg) if done then return Result() end done=true if string.find(errmsg,"Cancelled") then p(" User cancel.") p("") Result() else p("") p(errmsg) p("") Result() end return errmsg end function Result() if Rdone then return end Rdone=true if DisFil then behavior.SetSlowFiltersDisabled(false) end recentbest.Restore() Check() save.Quickload(1) band.DeleteAll() Tgain = (bestscore-startscore) if Tgain<0.008 then p(" No change.. :/ ") else p(" Startscore: "..cut(startscore)) p(" Score: "..cut(score())) p(" Total gain: "..cut(Tgain).." pts.") end setCI(cival) p("") p(" Undo once to restore bands") p("") end function bandpull(minBS,maxBS) local ss=score() local perc=math.random(100,180)/100 local loss=((perc*ss)/100) --p("",perc,cut(loss)) local lastBS=minBS for str=lastBS,maxBS, 0.1 do for i=1, band.GetCount() do band.SetStrength(i, str) end wig('wb',5) Check() save.Quicksave(76) recentbest.Restore() Check() save.Quickload(76) if (ss-score()>=loss) or (score()>bestscore+1) then if band.GetCount()>(nSegs/10)*2 then lastBS=str-0.1 if lastBS<minBS then lastBS=minBS end else lastBS=minBS end break end end end function main() p("") if band.GetCount()<1 then p(" Needs bands.") MakeSome() end save.Quicksave(1) save.Quicksave(startslot) recentbest.Save() cival=behavior.GetClashImportance() for mm=1, nSegs do if structure.IsMutable(mm) then MM = true break end end if DisFil then behavior.SetSlowFiltersDisabled(false) end startscore = score() bestscore = startscore p(" Startscore: "..cut(score())) p("") for i=1, band.GetCount() do local leng=band.GetLength(i) local perc=math.random(30,40) local loss=((perc*leng)/100) if band.GetGoalLength(i)==3.5 then band.SetGoalLength(i,band.GetLength(i)-loss) end end yy=0 R=0 while true do R=R+1 band.EnableAll() if band.GetCount()>1 then for b=1, band.GetCount() do RM=math.random(-100,100) if RM>=0 then BdOff=false else BdOff=true end if BdOff then band.Disable(b) end end end bandpull(0.2,3) band.DisableAll() recentbest.Save() if MM then save.Quicksave(93) setCI(.87) structure.MutateSidechainsAll(1) Check() setCI(cival) wig() Check() setCI(cival/2) wig("wa",5) Check() setCI(cival) wig() Check() wig('s') Check() wig() Check() save.Quickload(93) end setCI(cival/2) wig("wa",5) Check() setCI(cival) wig('s') Check() wig() Check() setCI(cival/2) wig("wa",5) Check() setCI(cival) wig() Check() wig('s') Check() wig() Check() recentbest.Restore() Check() if (score()-startscore<=minGain) or (bestscore-startscore<=minGain) then yy=yy+1 if yy>=badloops then save.Quickload(1) yy=0 end p("",R,cut(score())) else save.Quickload(1) yy=0 p("",R,cut(score())) end end Result() end IterationMultiplier = 1.2 -- 2.4 ItMu = IterationMultiplier badloops = 10 -- restore best after x bad loops minGain = 2 -- points gain needed for a loop to not be considered bad DisFil = false -- true or false, disable filters during wiggle startslot = 3 -- startpoint storage err=xpcall(main,End)

Comments


MurloW Lv 1

.
More bands = more profit

Quite handy for contact puzzles: Band selected cells -> start recipe.

Behavior on mutable puzzles: pulls bands -> quicksave(93) -> mutate + qstab -> quickload(93) -> qstab -> restore best