Icon representing a recipe

Recipe: AFK3(BounceWiggle)

created by Enzyme

Profile


Name
AFK3(BounceWiggle)
ID
102473
Shared with
Public
Parent
AFK3(BounceWiggle)
Children
Created on
September 13, 2017 at 23:20 PM UTC
Updated on
September 13, 2017 at 23:20 PM 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.BounceWiggle.MinGain = 0 AFK.BounceWiggle.SkipCIMaximization = true 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("BounceWiggle") currentDialog.IterationsLabel = dialog.AddLabel("Failed Iterations before ending") currentDialog.IterationsSlider = dialog.AddSlider("Failure Iterations", AFK.BounceWiggle.Iterations, 0, 1000, 1) 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.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 AFK.BounceWiggle.MinGain = currentDialog.DiscardSlider.value AFK.BounceWiggle.SkipCIMaximization = currentDialog.SkipMaximization.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 end AFK.BounceWiggle.Init = function() local choice = AFK.CreateBounceWiggleDialog() if(choice < 1) then return end local currentScore = AFK.StartScore local tempScore = currentScore local tempScore2 = tempScore save.Quicksave(98) recentbest.Save() behavior.SetClashImportance(1) local init = true if(AFK.BounceWiggle.SkipCIMaximization == 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() tempScore = currentScore tempScore2 = tempScore selection.SelectAll() structure.WiggleAll(25) recentbest.Restore() tempScore = current.GetEnergyScore() if(tempScore > (tempScore2 + AFK.BounceWiggle.MinGain)) then save.Quicksave(98) tempScore2 = tempScore else save.Quickload(98) tempScore = current.GetEnergyScore() end structure.LocalWiggleAll(25) recentbest.Restore() tempScore = current.GetEnergyScore() if(tempScore > (tempScore2 + AFK.BounceWiggle.MinGain)) then save.Quicksave(98) tempScore2 = tempScore else save.Quickload(98) tempScore = current.GetEnergyScore() end structure.WiggleSelected(25) recentbest.Restore() tempScore = current.GetEnergyScore() if(tempScore > (tempScore2 + AFK.BounceWiggle.MinGain)) then save.Quicksave(98) tempScore2 = tempScore else save.Quickload(98) tempScore = current.GetEnergyScore() end structure.LocalWiggleSelected(25) recentbest.Restore() tempScore = current.GetEnergyScore() if(tempScore > (tempScore2 + AFK.BounceWiggle.MinGain)) then save.Quicksave(98) tempScore2 = tempScore else save.Quickload(98) tempScore = current.GetEnergyScore() end end currentScore = current.GetEnergyScore() end if(currentScore > AFK.StartScore)then print ("script started: + "..(currentScore - AFK.StartScore).." -- "..currentScore) else print("script started: "..currentScore) 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(AFK.BounceWiggle.SkipCIMaximization == 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() tempScore = currentScore tempScore2 = tempScore selection.SelectAll() structure.WiggleAll(25) recentbest.Restore() tempScore = current.GetEnergyScore() if(tempScore > (tempScore2 + AFK.BounceWiggle.MinGain)) then save.Quicksave(98) tempScore2 = tempScore else save.Quickload(98) tempScore = current.GetEnergyScore() end structure.LocalWiggleAll(25) recentbest.Restore() tempScore = current.GetEnergyScore() if(tempScore > (tempScore2 + AFK.BounceWiggle.MinGain)) then save.Quicksave(98) tempScore2 = tempScore else save.Quickload(98) tempScore = current.GetEnergyScore() end structure.WiggleSelected(25) recentbest.Restore() tempScore = current.GetEnergyScore() if(tempScore > (tempScore2 + AFK.BounceWiggle.MinGain)) then save.Quicksave(98) tempScore2 = tempScore else save.Quickload(98) tempScore = current.GetEnergyScore() end structure.LocalWiggleSelected(25) recentbest.Restore() tempScore = current.GetEnergyScore() if(tempScore > (tempScore2 + AFK.BounceWiggle.MinGain)) then save.Quicksave(98) tempScore2 = tempScore else save.Quickload(98) tempScore = current.GetEnergyScore() end 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 currentScore = current.GetEnergyScore() local tempScore = currentScore local tempScore2 = tempScore save.Quicksave(98) --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() tempScore = current.GetEnergyScore() if(tempScore > (tempScore2 + AFK.BounceWiggle.MinGain)) then save.Quicksave(98) tempScore2 = tempScore else save.Quickload(98) tempScore = current.GetEnergyScore() end 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


Enzyme2 Lv 1

Updated for sketchbook puzzles. Now has a slider so you can determine a point threshhold to disregard. 0.5 worked well in my testing.