Icon representing a recipe

Recipe: Kuwaga Repeat Settle 2.94 crbest (LuaV2)

created by WBarme1234

Profile


Name
Kuwaga Repeat Settle 2.94 crbest (LuaV2)
ID
104368
Shared with
Public
Parent
None
Children
Created on
January 20, 2021 at 14:43 PM UTC
Updated on
January 20, 2021 at 14:43 PM UTC
Description

Repeat settle improved
with check lost points
along ranked best

Best for


Code


--Based on Recipe 'Kuwaga Repeat Settle 0.93' -- V2.93 - converted to Lua V2 -- V2.94 - improved with function compare_scores1 (2017) start_it = 3 --minimal freezes start_in_depth_walking_at = 1000 -- high = always, 0 = never local_wiggle_min_depth = 8 local_wiggle_max_depth = 25 global_wiggle_min_depth = 8 global_wiggle_max_depth = 25 wiggle_harder = false --always wiggle harder (=finds more points, runs slower, -- enable when normal mode doesn't give enough points anymore) skip_optimize = false --skip global wiggles scoreBestRanked= -999998.9 lscoreBestRanked= -999999.9 currentScore= -999999.9 scoreAtbestRanked= false scorebestchge = true sc= structure.GetCount() last_tot = 0 last_hi = 0 roundup = false word = " " init_score = current.GetScore() hi_score = current.GetScore() -- help() function compare_scores1 ( ) recentbest.Restore() score = current.GetScore() if (score > hi_score) then rec_imp = score - hi_score rec_imp = rec_imp - rec_imp % 0.001 tot_imp = score - init_score tot_imp = tot_imp - tot_imp % 0.001 if (rec_imp > 0) then print("Got ", word, rec_imp ," points! Total gain: ", tot_imp, " - Score at: ", score) word = "another " else if (last_tot < tot_imp) then print("Got ", word, "0.001 points! Total gain: ", tot_imp, " - Score at: ", score) word = "another " end end last_tot = tot_imp hi_score = score skip_optimize = false end end function compare_scores() compare_scores1() currentScore = current.GetScore() -- Get current(actual) Score -- print(" - Current Score : "..currentScore) scoreBestRanked = creditbest.GetScore() -- print(" - Credited best Ranked Score : "..scoreBestRanked) -- Verify, if best ranked score reached if ( math.abs(scoreBestRanked - currentScore) < 1E-6) then scoreAtbestRanked = true -- Set bit: Recipe started or running along best ranked score end -- print(" - Running along my own best ranking =",scoreAtbestRanked) if ( scoreAtbestRanked and (scoreBestRanked>currentScore) and (lscoreBestRanked<scoreBestRanked) ) then creditbest.Restore() -- regain lost points print("Reseting to CreditBest-RankedScore - due to lost points detected") compare_scores1() end lscoreBestRanked = scoreBestRanked end function freeze_every_nth_starting_from_x(n,x) recentbest.Restore() selection.DeselectAll() freeze.UnfreezeAll() for i=x, sc, n do if not (i == 0) then selection.Select(i) end end freeze.FreezeSelected(true,true) recentbest.Save() end function local_wiggle_every_nth_starting_from_x(n,x) if x > 1 then selection.DeselectAll() selection.SelectRange(1,x-1) wiggle_for_points("lw",local_wiggle_min_depth,local_wiggle_max_depth) end for i=x+1, sc, n do selection.DeselectAll() end_sel = i + n - 2 if (end_sel < i) then end_sel = i end if (end_sel > sc) then end_sel = sc end selection.SelectRange(i,end_sel) wiggle_for_points("lw",local_wiggle_min_depth,local_wiggle_max_depth) end end function wiggle_walk(n,x) --print(x,"/",n) freeze_every_nth_starting_from_x(n,x) local_wiggle_every_nth_starting_from_x(n,x) end function wiggle_for_points(type,min_depth,max_depth) if (wiggle_harder == true) and type == "lw"then mp = 3 else mp = 1 end repeat ps = current.GetScore() if type == "sh" then structure.ShakeSidechainsSelected(min_depth*mp) end if type == "ws" then structure.LocalWiggleSelected(min_depth*mp,0,1) -- wiggle sidechains end if type == "wb" then structure.LocalWiggleSelected(min_depth*mp,1.0) -- wiggle backbone end if type == "wa" then structure.LocalWiggleSelected(min_depth*mp,0,0) -- wiggle all end if type == "lw" then structure.LocalWiggleSelected(min_depth*mp) end mp = mp + 1 until (mp*min_depth>max_depth) or (ps >= current.GetScore()) compare_scores() end function optimize() recentbest.Restore() freeze.UnfreezeAll() selection.DeselectAll() recentbest.Save() selection.SelectRange(1,sc) save.Quicksave(3) debsc = hi_score wiggle_for_points("sh",global_wiggle_min_depth,global_wiggle_max_depth) wiggle_for_points("ws",global_wiggle_min_depth,global_wiggle_max_depth) wiggle_for_points("wb",global_wiggle_min_depth,global_wiggle_max_depth) wiggle_for_points("ws",global_wiggle_min_depth,global_wiggle_max_depth) wiggle_for_points("wa",global_wiggle_min_depth,global_wiggle_max_depth) if (debsc == hi_score) then skip_optimize = true end end print("Trying to improve your score...") freeze.UnfreezeAll() selection.DeselectAll() recentbest.Save() last_ct = 0 last_hi = 0 end_it = sc first = true behavior.SetClashImportance(1) repeat if (hi_score - last_hi) < 0.005 and not (wiggle_harder == true) then print("Repeating from start. This time wiggling harder!") wiggle_harder = true elseif first == false then print("Repeating from start...") end first = false last_hi = hi_score print(hi_score) if wiggle_harder == true then temp = end_it end_it = start_it start_it = temp dir = -1 else dir = 1 end for it = start_it, end_it, dir do ct = sc / it roundup = false if not (ct % 1 == ct) then ct = ct - ct % 1 + 1 roundup = true end if not (last_ct == ct) then if ct > start_in_depth_walking_at then wiggle_walk(ct,0) else half = ct/2 half = half + half % 1 for j = 1, half, 1 do --print(2*j-1,"/",ct) wiggle_walk(ct,j) if (ct>=j+half) then --print(2*j,"/",ct) wiggle_walk(ct,j+half) end end if (skip_optimize == false) then optimize() end end end last_ct = ct end until (last_hi == hi_score and wiggle_harder == true) selection.DeselectAll() freeze.UnfreezeAll() recentbest.Save() if scoreAtbestRanked then creditbest.Restore() end print("Try some other script")

Comments


Bruno Kestemont Lv 1

It works very well on end game on design puzzles that are very sensitive to changes in Buried polar, HBonds, core and idealize filters.