Icon representing a recipe

Recipe: Total LWS V2.0.3 - Alcor Edition!

created by Formula350

Profile


Name
Total LWS V2.0.3 - Alcor Edition!
ID
104226
Shared with
Public
Parent
Total LWS V2.0
Children
Created on
December 17, 2020 at 04:43 AM UTC
Updated on
December 17, 2020 at 04:43 AM UTC
Description

Lua V2 with dialog, good for filters and New Chapter
v2.0.1 - Alcor Edition
v2.0.2 - Alcor Edition with INPUT BOXES! (original Slider style
commented-out in code)
v2.0.3 - Fixes a starting error, and makes "Keep structures"
checkbox function correctly

Best for


Code


--Formula350 screwed up again, I see! Goofup is on Line --> --^^^ Lua sucks at handling errors, so I made it more helpful! (It'll produce this when canceling, too, cuz... Lua!) --Total LWS V2.0 --Based on Total LWS 1.0.4. by Rav3n_pl --Bruno Kestemont 6 Feb 2013 --adapted to NC + minppi diminishes with loops 01/02/2014 --------------------------------------------------------------------------------------- --Generic parameters and functions p=print --"quicker" print segCnt=structure.GetCount() --runnum=1 --minlen=1 --maxlen=7 --minppi=0.01 --NotAllLoops=true timeLeft=os.difftime(puzzle.GetExpirationTime(),os.time())/86400 startTime=os.time() PROBABLEFILTER=false OriginalFilterSetting = behavior.GetSlowFiltersDisabled() -- new BK 8/4/2013 function Score() return current.GetEnergyScore() end startingscore= Score() function down1(x)--cut all afer 1-rd place return x-x%0.1 end function down(x) return x-x%1 end function detectfilter() local descrTxt=puzzle.GetDescription() if #descrTxt>0 and (descrTxt:find("filter") or descrTxt:find("filters")) then PROBABLEFILTER=true end return end detectfilter() function AllLoop() local ok=false -- First save structure ! for i=1, segCnt do local ss=structure.GetSecondaryStructure(i) if ss~="L" then save.SaveSecondaryStructure() ok=true break end end if ok then selection.SelectAll() structure.SetSecondaryStructureSelected("L") end end function lw(minppi) local gain=true while gain do local ss=Score() if PROBABLEFILTER then behavior.SetSlowFiltersDisabled(true) end-- new BK 8/4/2013, always disable filter here structure.LocalWiggleSelected(2) --structure.WiggleSelected if PROBABLEFILTER then behavior.SetSlowFiltersDisabled(OriginalFilterSetting) end -- new BK 8/4/2013, always back to user settings local g=Score()-ss if g<tonumber(minppi) then gain=false end if g<0 then recentbest.Restore() end end selection.DeselectAll() -- new freeze.UnfreezeAll() -- new end --Total lws function totalLws(minlen,maxlen,minppi) local function Freeze(start, len) freeze.UnfreezeAll() selection.DeselectAll() for f=start, segCnt, len+1 do if f<= segCnt then selection.Select(f) end end freeze.FreezeSelected(true, false) end local function wiggle(start,len,minppi) if start>1 then selection.DeselectAll() selection.SelectRange(1,start-1) lw(minppi) end for i=start, segCnt, len+1 do selection.DeselectAll() local ss = i+1 local es=i+len if ss >= segCnt then ss=segCnt end if es >= segCnt then es=segCnt end selection.SelectRange(ss,es) lw(minppi) end end freeze.UnfreezeAll() selection.DeselectAll() behavior.SetClashImportance(1) save.SaveSecondaryStructure() if NotAllLoops~=true then AllLoop() end local ssc=Score() p("Starting Total LWS: "..ssc) p("length: "..minlen.." to "..maxlen.." ;minimum ppi: "..minppi) for l=minlen, maxlen do for s=1, l+1 do p("Len: "..l.."..start point: "..s) Freeze(s,l) local sp=Score() recentbest.Save() wiggle(s,l,minppi) local g=Score()-sp p("Gained another: "..g) end end p("Total LWS gain: "..Score()-ssc) save.LoadSecondaryStructure() end function AskOptions() local ask=dialog.CreateDialog("Total LWS Options") --repeat -- TO USE THE SLIDERS VERSION... Uncomment (delete the --) infront of the "ask.", and add them in front of "INPUT BOX VERSION". --ask.minlen=dialog.AddSlider(" MIN length",1,1,25,0) -- Alcor, values are thus: ("title",default,min,max,decimals) --ask.maxlen=dialog.AddSlider(" MAX length",7,1,25,0) -- The 'decimals' is how many decimal places the slider uses. --ask.minppi=dialog.AddSlider(" Min Points/Int",0.01,0.001,5,3) -- So a value of 0 is a whole number, and 3 is 0.123 --ask.runnum=dialog.AddSlider(" # of Runs",10,1,20,0) -- INPUT BOX VERSION ask.minlen=dialog.AddTextbox(" MIN length","") -- Textbox is: ("title",default) ask.maxlen=dialog.AddTextbox(" MAX length","") -- Setting the 'default' place to "" means no value displayed ask.minppi=dialog.AddTextbox(" Min Points/Int","") -- (I don't know what -1 means! heh) ask.runnum=dialog.AddTextbox(" # of Runs",5) -- Original code... --ask.minlen=dialog.AddSlider("min length",1,1,25,0) --ask.maxlen=dialog.AddSlider("max length",7,6,25,0) --ask.minppi=dialog.AddSlider("Min points per iteration",0.1,0.01,3,2) --ask.runnum=dialog.AddSlider("Number runs",1,1,5,0) ask.NotAllLoops = dialog.AddCheckbox("Keep structure",true) ask.OK = dialog.AddButton("OK",1) ask.Cancel = dialog.AddButton("Cancel",0) askresult=dialog.Show(ask) --until askresult<2 --return askresult > 0 --end if askresult > 0 then minlen=ask.minlen.value -- minimum lenggh of sgmnts - if you have done lws by 1 and 2 you may want set it to 3 maxlen=ask.maxlen.value --segCntmum length of sgments - more than 7 looks useless minppi=ask.minppi.value --minimum gain per local wiggle iter runnum=ask.runnum.value NotAllLoops=ask.NotAllLoops.value print("Options:minlen =",minlen,", maxlen =",maxlen,", minppi =",minppi, ", runnum =",runnum, ", NotAllLoops =",NotAllLoops) return true end return false end if AskOptions()==false then return end --M A I N ----- --AskOptions() while(true) do for i=1, runnum do print("run "..i.." / "..runnum) totalLws(minlen,maxlen,minppi) minppi=minppi*(1-(1/runnum)) -- new 01/02/2014 end end --recipe.ReportStatus() duration=(os.time()-startTime)/60 -- in minutes score=Score() Recipegain=score-startingscore RecipeReturn=Recipegain/duration*60 -- in pts/hour print("Duration = "..down(duration).." min. Return= "..down1(RecipeReturn).." pts/hour.")

Comments


Formula350 Lv 1

Helped me fix (see: he figured out the issue and solution, I typed it in) the reason it wouldn't run after starting and fixed Bruno's "Keep structures" checkbox from doing the opposite of what was intended. :)