Icon representing a recipe

Recipe: AFK3(BounceWiggle)

created by Enzyme

Profile


Name
AFK3(BounceWiggle)
ID
102456
Shared with
Public
Parent
None
Children
Created on
August 22, 2017 at 00:44 AM UTC
Updated on
August 22, 2017 at 00:44 AM UTC
Description

Random Clashing Importance Wiggles/Shakes. Useful when you don't feel like CI wiggling by hand.

Best for


Code


AFK = {} AFK.BounceWiggle = {} AFK.Debug = {} AFK.Init = {} AFK.Init.IsSelected = {} AFK.Init.IsFrozen = {} AFK.BounceWiggle.DoShake = false AFK.IsMutable = false AFK.BounceWiggle.DoMutate = false AFK.BounceWiggle.Iterations = 50 AFK.Debug.DoDebug=false AFK.CreateBounceWiggleDialog = function() for n=1,structure.GetCount() do if(structure.IsMutable(n)) then AFK.IsMutable = true end if(selection.IsSelected(n)) then AFK.Init.IsSelected[n] = true else AFK.Init.IsSelected[n] = false end if(freeze.IsFrozen(n)) then AFK.Init.IsFrozen[n] = true else AFK.Init.IsFrozen[n] = false end end local currentDialog = dialog.CreateDialog("Bounce Wiggle") currentDialog.IterationsLabel = dialog.AddLabel("Failed Iterations before ending") currentDialog.IterationsSlider = dialog.AddSlider("Failured Iterations", AFK.BounceWiggle.Iterations, 0, 1000, 1) currentDialog.SkipMaximization = dialog.AddCheckbox("Skip CI=1 Maximization", true) currentDialog.NoShakeButton = dialog.AddButton("No Shake", 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 if(AFK.BounceWiggle.Iterations < 1) then AFK.BounceWiggle.Iterations = -1 end if (choice > 2) then print("AFK3(BounceWiggleMutate) started. "..AFK.BounceWiggle.Iterations.." Failed Iterations before ending") AFK.BounceWiggle.DoMutate = true elseif (choice > 1) then print("AFK3(BounceWiggleShake) started. "..AFK.BounceWiggle.Iterations.." Failed Iterations before ending") AFK.BounceWiggle.DoShake = true elseif (choice > 0) then print("AFK3(BounceWiggleNoShake) started. "..AFK.BounceWiggle.Iterations.." Failed Iterations before ending") else print("Dialog cancelled") end return choice, currentDialog.SkipMaximization.value end AFK.BounceWiggle.Init = function() recentbest.Save() behavior.SetClashImportance(1) local currentScore = AFK.StartScore local choice, skipMaximize = AFK.CreateBounceWiggleDialog() if(choice < 1) then return end local init = true if(skipMaximize == false) then print("Maximizing Wiggle Score at Clashing Impotance = 1. Please wait.") while(current.GetEnergyScore() > currentScore or init == true) do init = false currentScore = current.GetEnergyScore() selection.SelectAll() structure.WiggleAll(25) recentbest.Restore() structure.LocalWiggleAll(25) recentbest.Restore() structure.WiggleSelected(25) recentbest.Restore() structure.LocalWiggleSelected(25) recentbest.Restore() end end currentScore = current.GetEnergyScore() if(current.GetEnergyScore() > AFK.StartScore)then print ("script started: + "..(current.GetEnergyScore() - AFK.StartScore).." -- "..current.GetEnergyScore()) else print("script started: "..current.GetEnergyScore()) end init = true while(init == true or AFK.BounceWiggle.Iterations > 0 or AFK.BounceWiggle.Iterations < 0) do init = false currentScore = current.GetEnergyScore() if(AFK.Debug.DoDebug == true) then print("Debug") end AFK.BounceWiggle.Run() if(current.GetEnergyScore() > currentScore)then print (AFK.BounceWiggle.Iterations..": + "..(current.GetEnergyScore() - currentScore).." -- "..current.GetEnergyScore()) if(AFK.BounceWiggle.Iterations > 0) then AFK.BounceWiggle.Iterations = AFK.BounceWiggle.Iterations + 1 end else if(AFK.Debug.DoDebug == true) then --print ("CI("..ci..") "..co.."("..ce..") ".." CI(1) "..ca.."("..cu..") ") end end if(AFK.BounceWiggle.Iterations > 0) then AFK.BounceWiggle.Iterations = AFK.BounceWiggle.Iterations - 1 end end init = true currentScore = current.GetEnergyScore() if(skipMaximize == false) then print("Maximizing Wiggle Score at Clashing Impotance = 1. Please wait.") while(current.GetEnergyScore() > currentScore or init == true) do init = false currentScore = current.GetEnergyScore() selection.SelectAll() structure.WiggleAll(25) recentbest.Restore() structure.LocalWiggleAll(25) recentbest.Restore() structure.WiggleSelected(25) recentbest.Restore() structure.LocalWiggleSelected(25) recentbest.Restore() end end if(current.GetEnergyScore() > currentScore)then print ("script complete: + "..(current.GetEnergyScore() - AFK.StartScore).." -- "..current.GetEnergyScore()) else print("script complete:"..current.GetEnergyScore()) end AFK.Cleanup() end AFK.BounceWiggle.Run = function() local highscore = current.GetEnergyScore() --truly random numbers are not required local wiggle1Type = math.random(1,4) local wiggle1Iterations = math.random(1, 3) local wiggle1CI = math.random(1, 1000) / 1000 local wiggle2Type = math.random(1,4) if(AFK.Debug.DoDebug == true) then print("wiggle1Type "..wiggle1Type) print("wiggle1Iterations "..wiggle1Iterations) print("wiggle1CI "..wiggle1CI) print("wiggle2Type "..wiggle2Type) end behavior.SetClashImportance(wiggle1CI) if(wiggle1Type > 3) then structure.LocalWiggleSelected(wiggle1Iterations) --wiggle1Type = "LocalWiggleSelected" elseif(wiggle1Type > 2) then structure.WiggleSelected(wiggle1Iterations) --wiggle1Type = "LocalWiggleSelected" elseif(wiggle1Type > 1) then structure.LocalWiggleAll(wiggle1Iterations) --wiggle1Type = "LocalWiggleSelected" else structure.WiggleAll(wiggle1Iterations) --wiggle1Type = "LocalWiggleSelected" end if(AFK.BounceWiggle.DoShake == true or AFK.BounceWiggle.DoMutate == true) then local shakeType = math.random(1,3) local shakeIterations = math.floor(((wiggle1Type + wiggle2Type) / 2) + 0.5) local shakeCI = math.random(1, 1000) / 1000 behavior.SetClashImportance(shakeCI) if(AFK.Debug.DoDebug == true) then print("shakeType "..shakeType) print("shakeIterations "..shakeIterations) print("shakeCI "..shakeCI) end if(shakeType > 1 and AFK.BounceWiggle.DoMutate == true) then structure.MutateSidechainsAll(shakeIterations) elseif(shakeType > 1) then structure.ShakeSidechainsAll(shakeIterations) else selection.DeselectAll() local shakeSelectionCount = math.random(1,structure.GetCount()) if(AFK.Debug.DoDebug == true) then print("shakeSelectionCount "..shakeSelectionCount) end for n=1,shakeSelectionCount do local selectSegment = math.random(1,structure.GetCount()) if(AFK.Debug.DoDebug == true) then print("selectSegment "..selectSegment) end selection.Select(selectSegment) end if(AFK.BounceWiggle.DoMutate == true) then structure.MutateSidechainsSelected(shakeIterations) else structure.ShakeSidechainsSelected(shakeIterations) end selection.SelectAll() end end behavior.SetClashImportance(1) if(AFK.Debug.DoDebug == true) then print("wiggle2Type "..wiggle2Type) end if(wiggle2Type > 3) then structure.LocalWiggleSelected(25) --wiggle2Type = "LocalWiggleSelected" elseif(wiggle2Type > 2) then structure.WiggleSelected(25) --wiggle2Type = "WiggleSelected" elseif(wiggle2Type > 1) then structure.LocalWiggleAll(25) --wiggle2Type = "LocalWiggleAll" else structure.WiggleAll(25) --wiggle2Type = "WiggleAll" end recentbest.Restore() end AFK.StartScore = current.GetEnergyScore() AFK.StartCI = behavior.GetClashImportance() function AFK.Cleanup(errorMessage) behavior.SetClashImportance(AFK.StartCI) recentbest.Restore() --selection.DeselectAll() for n=1,structure.GetCount() do if(AFK.Init.IsSelected[n] == true) then selection.Select(n) else selection.Deselect(n) end if(AFK.Init.IsFrozen[n] == true) then freeze.Freeze(n, true, true) else freeze.Unfreeze(n, true, true) end end end xpcall(AFK.BounceWiggle.Init, AFK.Cleanup)

Comments