Icon representing a recipe

Recipe: AFK3.1.1(BounceWiggle)JonForfeits.Lua

created by zo3xiaJonWeinberg

Profile


Name
AFK3.1.1(BounceWiggle)JonForfeits.Lua
ID
103796
Shared with
Public
Parent
AFK3.1.1(BounceWiggle)
Children
Created on
August 10, 2020 at 17:29 PM UTC
Updated on
August 10, 2020 at 17:29 PM UTC
Description

Jon: When exporting recipes (at least on Mac), you must select the folder to save the recipe in, because otherwise I think Foldit tries to overwrite your most recent file (which is selected in grey) and crashes, and then I must force-quit Foldit from the Apple button. Also never press Enter while Setting Info of a recipe as that also crashes. Instead press Shift-Enter to enter a new line of text. Also, it's easier to modify a recipe by exporting it and naming it as a .Lua file then editing it with Sublime Text Editor, then in Foldit pressing Edit, Load, Import because Foldit's text editor isn't great, even compared to Emacs (which is great just not on Mac, ironically).

Jon's only uncommented modifications of the recipe: the script now resigns and resets the puzzle if no score improvement for a while (>3 iterations), then continues the recipe. Necessary for multistart puzzles to be fully automated. It is also helpful in single-start puzzles as well and for scientists to see diverse solutions.
Since the recipe restarts when it gets stuck, I figured it can run for a longer time so I increased the runtime. But after hours of running with no additional increase in points, I canceled and ran shake (on a design puzzle) and the points increased, so I figure shake should go after mutate so I included that.

I don't mean to call this recipe my own; I just make edit many unfamiliar recipes so putting my name in the title or comments where I made modifications helps me keep track of my changes in case I ever mess something up. It also helps me avoid accidentally overwriting the original recipe files on my computer.

Marsfan's recipe. Marsfan's notes:
Random Clashing Importance Wiggles/Shakes. Useful when you don't feel like CI wiggling by hand.

Changes from parent: Reports failed iterations, disables slow filters whenever performing tasks on protein (wiggle, shake, mutate, etc)

Best for


Code


--------------- -- Variables -- --------------- AFK = {} AFK.SaveSlot = 98 AFK.StartScore = current.GetEnergyScore() AFK.StartCI = behavior.GetClashImportance() AFK.IsMutable = false AFK.BounceWiggle = {} AFK.Init = {} AFK.Helper = {} AFK.BounceWiggle.DoShake = false AFK.BounceWiggle.DoMutate = false AFK.BounceWiggle.Iterations = 500 --jon 50->500 AFK.BounceWiggle.MinGain = 0.1 AFK.BounceWiggle.SkipCIMaximization = true AFK.BounceWiggle.PrintFailures = true ---------------------- -- Helper Functions -- ---------------------- AFK.Helper.IsMutable = function() for n=1, structure.GetCount() do if (structure.IsMutable(n)) then AFK.IsMutable = true end end end AFK.Helper.PrintStart = function(choice) if (choice > 2) then mode = "Mutate" AFK.BounceWiggle.DoMutate = true elseif (choice > 1) then mode = "Shake" AFK.BounceWiggle.DoShake = true else mode = "NoShake" end print("AFK3(BounceWiggle"..mode..") started. ".. AFK.BounceWiggle.Iterations.. " Failed iterations before ending.") end AFK.Helper.PrintEnd = function(gain) if (gain > 0) then print ("script complete: + ".. (current.GetEnergyScore() - AFK.StartScore).. " -- "..current.GetEnergyScore()) else print("script complete:"..current.GetEnergyScore()) end end AFK.Helper.SetCI = function(ci) ci = ci or math.random(50, 900) / 1000 behavior.SetClashImportance(ci) end AFK.Helper.SelectRandom = function() local shakeSelectionCount = math.random(1, structure.GetCount()) for n=1, shakeSelectionCount do local selectSegment = math.random(1, structure.GetCount()) selection.Select(selectSegment) end end AFK.Helper.PerformFunction = function(func, iters) local currentScore = current.GetEnergyScore() local newScore = currentScore behavior.SetFiltersDisabled(true) func(iters) behavior.SetFiltersDisabled(false) recentbest.Restore() newScore = current.GetEnergyScore() if (newScore > (currentScore + AFK.BounceWiggle.MinGain)) then currentScore = newScore save.Quicksave(AFK.SaveSlot) else save.Quickload(AFK.SaveSlot) end end --Jon copied (and changed p to print to avoid crashing) from Rav3n_pl-GAB-Jon12Kuai.Lua function fullReset() puzzle.StartOver() --reset_puzzle --should also work behavior.SetClashImportance(1) --clash behavior.SetWigglePower("a") --auto --overwrite previous for clean save.Quicksave(AFK.SaveSlot) save.Quicksave(3) save.Quicksave(4) save.Quicksave(5) save.Quicksave(6) --jon's print("puzzle reset, which will restart in a new starting point if multistart.") print("Player " .. user.GetPlayerName() .." has forfeited the game but not the match. Restarting...") --Jon copied command from Bruno Kestomont's JET 3.6 ui.CenterViewport() --same as Q hotkey, Jon copied from LociOiling's clean 1.0 recipe recentbest.Save() --to prevent loading from the local minimum end dogDays=0 --Jon's var. def: "2. A period of stagnation." -TheFreeDictionary AFK.Helper.UpdateIterations = function(gain) -- TODO: option to print, even on failure. (so we know Iterations) if gain > 0 then dogDays=0 print (AFK.BounceWiggle.Iterations..": + ".. gain.." -- "..current.GetEnergyScore()) elseif (AFK.BounceWiggle.Iterations > 0) then if (AFK.BounceWiggle.PrintFailures == true) then print(AFK.BounceWiggle.Iterations..": "..gain.." -- "..current.GetEnergyScore()) end AFK.BounceWiggle.Iterations = AFK.BounceWiggle.Iterations - 1 --jon if(dogDays > 2) then --2) then print("entering reset") fullReset() --Jon dogDays=0 else dogDays=dogDays+1 end --++ end end ----------------------- -- Create Dialog Box -- ----------------------- AFK.CreateBounceWiggleDialog = function() local currentDialog = dialog.CreateDialog("BounceWiggle") currentDialog.IterationsLabel = dialog.AddLabel( "Failed Iterations before ending") currentDialog.IterationsSlider = dialog.AddSlider( "Failure Iterations", AFK.BounceWiggle.Iterations, -1, 1000, 0) currentDialog.BlankLabel1 = dialog.AddLabel("") currentDialog.DiscardLabel = dialog.AddLabel( "(Sketchbook) Discard gains less than") currentDialog.DiscardSlider = dialog.AddSlider( "Discard <", AFK.BounceWiggle.MinGain, 0, 10, 1) currentDialog.BlankLabel2 = dialog.AddLabel("") currentDialog.SkipMaximization = dialog.AddCheckbox( "Skip CI=1 Maximization", AFK.BounceWiggle.SkipCIMaximization) currentDialog.PrintFailuresOption = dialog.AddCheckbox( "Print info for Failed Attempts", AFK.BounceWiggle.PrintFailures ) currentDialog.NoShakeButton = dialog.AddButton("Wiggle Only", 1) currentDialog.ShakeButton = dialog.AddButton("Shake", 2) if (AFK.IsMutable) then currentDialog.MutateButton = dialog.AddButton("Mutate+shake", 3) end currentDialog.CancelButton = dialog.AddButton("Cancel", 0) local choice = dialog.Show(currentDialog) AFK.BounceWiggle.Iterations = currentDialog.IterationsSlider.value AFK.BounceWiggle.MinGain = currentDialog.DiscardSlider.value AFK.BounceWiggle.SkipCIMaximization = currentDialog.SkipMaximization.value AFK.BounceWiggle.PrintFailures = currentDialog.PrintFailuresOption.value if (AFK.BounceWiggle.Iterations < 1) then AFK.BounceWiggle.Iterations = -1 end if (choice > 0) then AFK.Helper.PrintStart(choice) end return choice end ------------------- -- The main dish -- ------------------- AFK.BounceWiggle.Main = function() AFK.Helper.IsMutable() local startScore = AFK.StartScore local choice = AFK.CreateBounceWiggleDialog() if (choice < 1) then print("Dialog cancelled.") return end save.Quicksave(AFK.SaveSlot) recentbest.Save() if (AFK.BounceWiggle.SkipCIMaximization == false) then AFK.Helper.PerformFunction(AFK.BounceWiggle.CIMaximization) startScore = current.GetEnergyScore() end print("Script started: "..startScore) while (AFK.BounceWiggle.Iterations ~= 0) do startScore = current.GetEnergyScore() AFK.Helper.PerformFunction(AFK.BounceWiggle.BounceWiggle) AFK.Helper.UpdateIterations(current.GetEnergyScore() - startScore) end AFK.Helper.PrintEnd(current.GetEnergyScore() - startScore) AFK.Cleanup() end ------------------------- -- The BounceWiggliest -- ------------------------- AFK.BounceWiggle.CIMaximization = function() local currentScore = AFK.StartScore local newScore = currentScore + AFK.BounceWiggle.MinGain + 0.01 print("Maximizing Wiggle Score at Clashing Importance = 1: "..currentScore) AFK.Helper.SetCI(1) while (currentScore + AFK.BounceWiggle.MinGain < newScore) do structure.WiggleAll(25) structure.LocalWiggleAll(25) recentbest.Restore() currentScore = newScore newScore = current.GetEnergyScore() end if (newScore > AFK.StartScore) then print ("CI Maximization: + "..(currentScore - AFK.StartScore).. " -- "..currentScore) end end AFK.BounceWiggle.WiggleAll = function(ci, wiggleIterations) AFK.Helper.SetCI(ci) wiggleIterations = wiggleIterations or math.random(1, 3) local wiggleType = math.random(1, 2) if (wiggleType > 1) then structure.WiggleAll(wiggleIterations) else structure.LocalWiggleAll(wiggleIterations) end end AFK.BounceWiggle.ShakeityShake = function() local shakeType = math.random(1, 3) local shakeIterations = math.random(1, 3) AFK.Helper.SetCI() local selectionLength=1 --jon's variable --jon copied from AILearnsToPlayFoldit local startSegmentNumber = math.random(1, structure.GetCount() - selectionLength) selection.DeselectAll() selection.SelectRange(startSegmentNumber, startSegmentNumber + selectionLength) -- 1/3 chance of whole protein --Jon overwriting because mutate is interesting to watch but only in moderation if (shakeType > 2 ) then --or true) then --Jon obstinately avoiding mass mutate and shake if (AFK.BounceWiggle.DoMutate == true) then -- When mutating all, we only do one iteration. -- This is to increase BounceWiggle speed, to explore more -- configurations faster. structure.MutateSidechainsAll(1) --Selected(1) --Jon changed SidechainsAll to Selected end --else --jon added the shake to mutate structure.ShakeSidechainsAll(shakeIterations) --Selected(1) --Jon: changed All->Selected, and shakeIterations->1 -- end --jon selection.DeselectAll() --Jon resetting from Jon's selection -- 2/3 chance of random selection else AFK.Helper.SelectRandom() if (AFK.BounceWiggle.DoMutate == true) then structure.MutateSidechainsSelected(shakeIterations) end --else --jon structure.ShakeSidechainsSelected(shakeIterations) -- end --jon selection.DeselectAll() end end AFK.BounceWiggle.BounceWiggle = function() AFK.BounceWiggle.WiggleAll() if (AFK.BounceWiggle.DoShake == true or AFK.BounceWiggle.DoMutate == true) then AFK.BounceWiggle.ShakeityShake() end AFK.BounceWiggle.WiggleAll(1, 25) end ------------- -- The end -- ------------- function AFK.Cleanup(errorMessage) behavior.SetClashImportance(AFK.StartCI) recentbest.Restore() selection.DeselectAll() -- Re enable all filters behavior.SetFiltersDisabled(false) end xpcall(AFK.BounceWiggle.Main, AFK.Cleanup)

Comments