Profile
- Name
- arcsign - lock down best segments
- ID
- 37754
- Shared with
- Public
- Parent
- None
- Children
- Created on
- January 22, 2012 at 07:50 AM UTC
- Updated on
- January 22, 2012 at 07:50 AM UTC
- Description
locks down best segments. options at the top.
Best for
Code
-- Lockdown Best Segments
-- arcsign
--
-- Pretty much exactly what it says; finds the highest scoring segment or two
-- and wiggles them til they won't wiggle. Anymore.
p=print
minSeg=1
maxSeg=structure.GetCount()
startSeg=1
endSeg=maxSeg
numSegToLock=5 -- number of segments to wiggle senseless. arbitrary-ish.
wiggleIterations=2
numBuddies=2 -- wiggle this many segments to either side of selected
minGain=0.1
-- getPoints function borrowed/stolen directly from rav3n's Lucky LWS v2.5
-- and changed for LUA v2 functions
function getPoints()
t={}
p("Getting segment scores")
selection.DeselectAll()
freeze.UnfreezeAll()
for i=startSeg, endSeg do
save.Quicksave(25)
selection.DeselectAll()
selection.Select(i)
local segScore=current.GetSegmentEnergyScore(i)
t[#t+1]={i,segScore}
p("Segment: ",i," score: ",segScore)
end
p("Filled segment score table")
return t
end
-- again, thank you rav3n for this lovely sort function. (i changed it ever so slightly)
function Sort(tab,items)
if items>#tab then items=#tab end
tabLen=#tab
for x=1,items do
for y=x+1,tabLen do
if tab[x][2]<tab[y][2] then
tab[x],tab[y]=tab[y],tab[x]
end
end
end
return tab
end
-- not quite rav3n's.
function wig(minGain)
repeat
local startScore=current.GetEnergyScore() -- don't care about global gains
structure.LocalWiggleSelected(wiggleIterations)
local segGain=(current.GetEnergyScore()-startScore)
if segGain<0 then
recentbest.Restore()
end
until segGain<minGain
selection.DeselectAll()
end
-- ... yep.
function wiggle(s, minGain, numBuddies)
p("Wiggling segment: ",s)
selection.DeselectAll()
freeze.UnfreezeAll()
selection.Select(s)
wig(minGain)
local startScore=current.GetEnergyScore()
if numBuddies>0 then
for b=1, numBuddies do
selection.DeselectAll()
if s+b>endSeg then selection.SelectRange(s,endSeg)
else selection.SelectRange(s,s+b) end
wig(minGain)
if s-b<startSeg then selection.SelectRange(startSeg,s)
else selection.SelectRange(s-b,s) end
wig(minGain)
end
end
p("Segment gain: ",(current.GetEnergyScore()-startScore))
end
-- hey! this part could reasonably be considered partially mine! yay!
function LockBestSegments()
selection.DeselectAll()
freeze.UnfreezeAll()
startScore=current.GetEnergyScore()
bestSegTable=getPoints()
bestSegTable=Sort(bestSegTable,numSegToLock)
if numSegToLock>#bestSegTable then numSegToLock=#bestSegTable end
for i=1,numSegToLock do
local currentSeg=bestSegTable[i][1]
recentbest.Save()
wiggle(currentSeg, minGain, numBuddies)
end
p("Total gain: ", current.GetEnergyScore()-startScore)
selection.DeselectAll()
for i=1,numSegToLock do
local currentSeg=bestSegTable[i][1]
selection.Select(currentSeg)
end
freeze.FreezeSelected(true, true)
p("Segments affected have been frozen. Effected. Whatever.")
end
LockBestSegments()