Icon representing a recipe

Recipe: Band All in Place1.0

created by brow42

Profile


Name
Band All in Place1.0
ID
39443
Shared with
Public
Parent
None
Children
None
Created on
March 11, 2012 at 23:26 PM UTC
Updated on
March 11, 2012 at 23:26 PM UTC
Description

Bands every segment in place without removing old bands...lets you enable them as a group or randomly.

Best for


Code


--[[ * Band All Segments * Adds a zero-length band to every segment without * removing existing bands. If run repeatedly, each * set can be enabled separately, or a random mix. --]] options = { strength = 1.0, group = 1, nwiggle = 1 } title = 'Band All Segments 1.0' function GetCount() local n = structure.GetCount() while structure.GetSecondaryStructure(n) == 'M' do n = n - 1 end return n end function ZLB(iSeg) local s2,s3 local n = GetCount() if iSeg == 1 then s2,s3 = 2, 3 elseif iSeg == n then s2,s3 = n-1, n-2 else s2,s3 = iSeg+1,iSeg-1 end local iBand = band.Add(iSeg,s2,s3,0.01,0,0) band.SetGoalLength(iBand,0.01) band.SetStrength(iBand,options.strength) end function BandAll() band.DisableAll() local n = GetCount() for i = 1,n do ZLB(i) end end function Wiggle() structure.WiggleAll(options.nwiggle) end function Pick(n,k) local l = {} local m = {} for i=1,n do l[i] = i end for i = 1,k do local j = math.random(n) print(j,n) m[i] = l[j] l[j] = l[n] n = n - 1 end table.sort(m) return m end function Select() local nseg = GetCount() local nband = band.GetCount() local first,last = nseg * (options.group - 1) + 1, nseg * options.group if first > nband then return end if last > nband then last = nband end band.DisableAll() for i = first,last do band.Enable(i) band.SetStrength(i,options.strength) end end function RandomSelect() local nseg = GetCount() local nband = band.GetCount() if nband < nseg then nseg = nband end list = Pick(nband, nseg) band.DisableAll() for i = 1,#list do band.Enable(list[i]) band.SetStrength(list[i],options.strength) end end function MainDialog() d = dialog.CreateDialog(title) local nseg = GetCount() local nband = band.GetCount() if nband % nseg ~= 0 then d.warn = dialog.AddLabel('Warning, some bands have been added/missing') end d.label1 = dialog.AddLabel('Re-run this after each manual threading') local ngroups = math.ceil(nband / nseg) if ngroups > 1 then d.slider = dialog.AddSlider('Select Group:',options.group,1,ngroups,0) end d.nwiggle = dialog.AddSlider('# Wiggles:',options.nwiggle,1,10,0) d.strength = dialog.AddSlider('Band Str.:',options.strength,0.1,10,1) d.band = dialog.AddButton('Band \'Em',1) if ngroups > 0 then d.select = dialog.AddButton('Select',2) d.random = dialog.AddButton('Random',3) end d.wiggle = dialog.AddButton('Wiggle',4) d.quit = dialog.AddButton('Quit',5) local rc, group = dialog.Show(d), 1 if ngroups > 1 then options.group = d.slider.value end options.nwiggle = d.nwiggle.value options.strength = d.strength.value return rc end seed = os.time() % 100000 seed = 6597 print(puzzle.GetName(),current.GetScore()) print('Seed = ',seed) while true do local rc, group = MainDialog() if rc == 1 then BandAll() elseif rc == 2 then Select() elseif rc == 3 then RandomSelect() elseif rc == 4 then Wiggle() elseif rc == 5 then break end end

Comments


brow42 Lv 1

Requested by dkmfan, this is intended to turn different threading starts into different rubber band patterns. Each time you thread (WITHOUT resetting or quickloading) you run the script again and make a new set of bands. After you have all your starts banded, you can run the script again to pick any of the starts by enabling those bands. You can also pick a random group of bands to sort of average all the starts. Suggested by Marie S, a more complicated future algorithm could pick good combinations of bands.

If you add or remove bands by hand, the program won't know exactly where each group of bands starts or ends.