Profile
- Name
- AFK3.1.1(BounceWiggle)
- ID
- 103546
- Shared with
- Public
- Parent
- AFK3.1(BounceWiggle)
- Children
- Created on
- May 27, 2020 at 05:21 AM UTC
- Updated on
- May 27, 2020 at 05:21 AM UTC
- Description
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 = 50
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
AFK.Helper.UpdateIterations = function(gain)
-- TODO: option to print, even on failure. (so we know Iterations)
if gain > 0 then
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
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", 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()
-- 1/3 chance of whole protein
if (shakeType > 2) then
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)
else
structure.ShakeSidechainsAll(shakeIterations)
end
-- 2/3 chance of random selection
else
AFK.Helper.SelectRandom()
if (AFK.BounceWiggle.DoMutate == true) then
structure.MutateSidechainsSelected(shakeIterations)
else
structure.ShakeSidechainsSelected(shakeIterations)
end
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)