Icon representing a recipe

Recipe: TvdL Filterfuze 2.0

created by Timo van der Laan

Profile


Name
TvdL Filterfuze 2.0
ID
45842
Shared with
Public
Parent
None
Children
None
Created on
March 30, 2013 at 17:46 PM UTC
Updated on
March 30, 2013 at 17:46 PM UTC
Description

The DRW fuze but filters are off during wiggle. Has provisions to keep recentbest intact.

Best for


Code


-- TvdL Filterfuze 2.0 -- The fuze from my DRW but during wiggles filters are off -- Position stack module 1.0 -- uses slot 50 and higher Stackmin=50 StackMarks={} StackPos=50 function PushPosition() if StackPos==100 then print("Position stack overflow, exiting") exit() end save.Quicksave(StackPos) StackPos=StackPos+1 end function PopPosition() if StackPos==50 then print("Position stack underflow, exiting") exit() end StackPos=StackPos-1 save.Quickload(StackPos) end function PushMarkPosition() StackMarks[#StackMarks+1]=StackPos PushPosition() end function PopMarkPosition() if #StackMarks == 0 then print("No marked position found, just popping") else StackPos=StackMarks[#StackMarks]+1 StackMarks[#StackMarks]= nil end PopPosition() end function ClrTopPosition() if StackPos > 50 then StackPos=StackPos-1 end end -- Handy shorts module normal= (current.GetExplorationMultiplier() == 0) segCnt=structure.GetCount() segCnt2=segCnt while structure.GetSecondaryStructure(segCnt2)=="M" do segCnt2=segCnt2-1 end -- On request of gmn CIfactor=1 function CI(CInr) behavior.SetClashImportance(CInr*CIfactor) end function CheckCI() local ask=dialog.CreateDialog("Clash importance is not 1") ask.l1=dialog.AddLabel("Last change to change it") ask.l2=dialog.AddLabel("CI settings will be multiplied by set CI") ask.continue=dialog.AddButton("Continue",1) dialog.Show(ask) end if behavior.GetClashImportance() < 0.99 then CheckCI() end CIfactor=behavior.GetClashImportance() -- Score functions function Score(pose) if pose==nil then pose=current end local total= pose.GetEnergyScore() -- FIX for big negatives if normal then return total else return total*pose.GetExplorationMultiplier() end end function SegScore(pose) if pose==nil then pose=current end local total=8000 for i=1,segCnt2 do total=total+pose.GetSegmentEnergyScore(i) end return total end function RBScore() return Score(recentbest) end function round3(x)--cut all afer 3-rd place return x-x%0.001 end bestScore=Score() function SaveBest() local g=Score()-bestScore if g>0 then if g>0.01 then print("Gained another "..round3(g).." pts.") end bestScore=Score() save.Quicksave(3) end end recentbestscore=0 recentbestslot=49 function FilterOff() -- Filters off but remember current recent best PushPosition() recentbest.Restore() recentbestscore=Score() save.Quicksave(49) PopPosition() behavior.SetSlowFiltersDisabled(true) recentbest.Save() end function FilterOn() -- Filter on but compute new recent best and set it save.Quicksave(48) --Current pose recentbest.Restore() behavior.SetSlowFiltersDisabled(false) if recentbestscore > Score() then save.Quickload(49) end recentbest.Save() save.Quickload(48) end -- Wiggle function -- Note the extra parameter to be used if only selected parts must be done function Wiggle(h,i,m,o) if h~="s" then FilterOff() end WiggleFilter(h,i,m,o) if h~="s" then FilterOn() end end function WiggleFilter(how, iters, minppi,onlyselected) --score conditioned recursive wiggle/shake --fixed a bug, absolute difference is the threshold now if how==nil then how="wa" end if iters==nil then iters=6 end if minppi==nil then minppi=0.1 end if onlyselected==nil then onlyselected=false end if iters>0 then iters=iters-1 local sp=Score() if onlyselected then if how == "s" then -- Shake is not considered to do much in second or more rounds structure.ShakeSidechainsSelected(1) return elseif how == "wb" then structure.WiggleSelected(2,true,false) elseif how == "ws" then structure.WiggleSelected(2,false,true) elseif how == "wa" then structure.WiggleSelected(2,true,true) end else if how == "s" then -- Shake is not considered to do much in second or more rounds structure.ShakeSidechainsAll(1) return 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,true,true) end end if math.abs(Score()-sp) > minppi then return WiggleFilter(how, iters, minppi,onlyselected) end end end -- end of handy shorts module -- Standard Fuze module -- Picks up all gains by using recentbest function GetRB(prefun,postfun) if RBScore()> Score() then if prefun ~= nil then prefun() end recentbest.Restore() if postfun ~= nil then postfun() end end end function FuzeEnd(prefun,postfun) if prefun ~= nil then prefun() end CI(1) Wiggle("wa",1) Wiggle("s",1) Wiggle() GetRB(prefun,postfun) if postfun ~= nil then postfun() end SaveBest() end function Fuze1(ci1,ci2,prefun,postfun) if prefun ~=nil then prefun() end CI(ci1) Wiggle("s",1) CI(ci2) Wiggle("wa",1) if postfun ~= nil then postfun() end end function Fuze2(ci1,ci2,prefun,postfun) if prefun ~= nil then prefun() end CI(ci1) Wiggle("wa",1) CI(1) Wiggle("wa",1) CI(ci2) Wiggle("wa",1) if postfun ~= nil then postfun() end end function reFuze(scr,slot) local s=Score() if s<scr then save.Quickload(slot) else scr=s save.Quicksave(slot) end return scr end function Fuze(slot,prefun,postfun) local scr=Score() if slot == nil then slot=4 save.Quicksave(slot) end recentbest.Save() Fuze1(0.3,0.6,prefun,postfun) FuzeEnd(prefun,postfun) scr=reFuze(scr,slot) Fuze2(0.3,1,prefun,postfun) GetRB(prefun,postfun) SaveBest() scr=reFuze(scr,slot) Fuze1(0.05,1,prefun,postfun) GetRB(prefun,postfun) SaveBest() scr=reFuze(scr,slot) Fuze2(0.7,0.5,prefun,postfun) FuzeEnd() scr=reFuze(scr,slot) Fuze1(0.07,1,prefun,postfun) GetRB(prefun,postfun) SaveBest() reFuze(scr,slot) GetRB(prefun,postfun) SaveBest() end -- end standard Fuze module Version="2.0.0" print("Tvdl Filterfuze "..Version) print("Startscore: "..round3(Score())) Fuze() print("Endscore: "..round3(Score()))

Comments


Timo van der Laan Lv 1

On my first test this fuse gained only 30 pts, but had messed up Polar Core so the expectation score went a lot up. Ran the none version after it and that got a lot of points.
From the same position the none version got 150 pts but the Polar Core was still intact.