Profile
- Name
- CopyASave0
- ID
- 100354
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- December 04, 2014 at 06:29 AM UTC
- Updated on
- December 04, 2014 at 06:29 AM UTC
- Description
12/4/14 1217am midnight *0b.txt code
Best for
Code
-- CopyASave adapted 12/3/14 by jeff101
-- from 607pm 12/3/14 ListStructDiffs1c.txt code
-- last updated 12/4/14 1217am midnight
-- goal is to copy a saved structure
-- from one autosave or slot (beg_slot)
-- into memory, display info about it, and then copy it
-- to another autosave or slot (end_slot)
function Main()
local subscores,f1,ci,nn,ask,dialog_show_ask,res,ires,qflag,isok,gotbeg,gotend
local codename='CopyASave0'
local beg_slot='rb' -- slot/save to copy structure from
local end_slot=13 -- slot/save to copy structure to
local beg_str,end_str
ci=behavior.GetClashImportance()
print('Running '..codename..' on')
print('puzzle '..puzzle.GetName()..' with ID '..puzzle.GetPuzzleID())
print('and clashing importance = '..ci..' at '..os.date()..'.')
print(' ')
subscores=puzzle.GetPuzzleSubscoreNames()
print('The subscores available for each segment are:')
for nn=1,#subscores do
print(' '..subscores[nn])
end -- for nn
print('Subscores that equal 0 are not listed below.')
print(' ')
qflag=0
while qflag==0 do
ask = dialog.CreateDialog(codename)
ask.Label1a = dialog.AddLabel('beg_slot=quickslot/autosave to copy structure from.')
ask.Label1b = dialog.AddLabel('beg_slot=1-100 for a quickslot, rb for RecentBest, ')
ask.Label1c = dialog.AddLabel(' cb for CreditBest, vb for VeryBest. ')
ask.beg_slot = dialog.AddTextbox("beg_slot: ",beg_slot)
ask.Label2a = dialog.AddLabel('end_slot=quickslot/autosave to copy structure to. ')
ask.Label2b = dialog.AddLabel('end_slot=1-100 for a quickslot, rb for RecentBest. ')
ask.end_slot = dialog.AddTextbox("end_slot: ",end_slot)
ask.OK = dialog.AddButton("OK", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
dialog_show_ask = dialog.Show(ask)
if dialog_show_ask == 0 then qflag=1
else -- dialog_show_ask must be 1
print('Getting beg_slot from \''..ask.beg_slot.value..'\':')
gotbeg=0
for res in string.gmatch(ask.beg_slot.value,'[^rcvb%d]*([rcv%d][b%d]*)') do
-- just want the first value for res that has res=1-100,rb,cb,vb
if gotbeg==0 then
if is_int(res) then
print('res=\''..res..'\' is an integer.')
ires=res+0
res=ires
else
print('res=\''..res..'\' is not an integer.')
ires=0
end
if res=='rb' or res=='cb' or res=='vb' then isok=1
elseif ires>=1 and ires<=100 then isok=1
else
print(' ERROR: want beg_slot to be rb, cb, vb, or 1-100, not '..res..'.')
isok=0
end -- if res
if isok==1 then
print(' Got beg_slot='..res..'.')
beg_slot=res
gotbeg=1
end -- if isok
end -- if gotbeg
end -- for res
print(' ')
if gotbeg==1 then
print('Getting end_slot from \''..ask.end_slot.value..'\':')
gotend=0
for res in string.gmatch(ask.end_slot.value,'[^rb%d]*([r%d][b%d]*)') do
-- just want the first value for res that has res=1-100,rb
if gotend==0 then
if is_int(res) then
print('res=\''..res..'\' is an integer.')
ires=res+0
res=ires
else
print('res=\''..res..'\' is not an integer.')
ires=0
end
if res==beg_slot then
print(' ERROR: end_slot should not equal beg_slot='..beg_slot..'.')
isok=0
elseif res=='rb' then isok=1
elseif ires>=1 and ires<=100 then isok=1
else
print(' ERROR: want end_slot to be rb or 1-100, not '..res..'.')
isok=0
end -- if res
if isok==1 then
print(' Got end_slot='..res..'.')
end_slot=res
gotend=1
qflag=1
end -- if isok
end -- if gotend
end -- for res
print(' ')
end -- if gotbeg
end -- if dialog_show_ask
end -- while qflag==0
if dialog_show_ask==1 then
if beg_slot=='cb' then
beg_str='CreditBest'
creditbest.Restore() -- load CreditBest
elseif beg_slot=='rb' then
beg_str='RecentBest'
recentbest.Restore() -- load RecentBest
elseif beg_slot=='vb' then
beg_str='VeryBest'
absolutebest.Restore() -- load VeryBest
else
beg_str='Slot '..beg_slot
save.Quickload(beg_slot+0) -- load from quicksave slot beg_slot
end -- if beg_slot
print('===========================================================================================================')
f1=ReadPrintStruct(subscores,beg_str)
print('===========================================================================================================')
if end_slot=='rb' then
end_str='RecentBest'
recentbest.Save() -- save present structure to RecentBest
else
end_str='Slot '..end_slot
save.Quicksave(end_slot+0) -- save present structure to quicksave slot end_slot
end -- if tmp_slot
print('Copying structure from '..beg_str..' to '..end_str..'.')
end -- if dialog_show_ask == 1
print(' ')
print('All done at '..os.date()..'.')
end -- Main()
function ReadPrintStruct(subscores,nam)
local fn,n,nn,ss,aa,note,pflag
fn={}
fn.nam=nam
fn.rtot=structure.GetCount()
fn.nbands=band.GetCount()
fn.expmul=current.GetExplorationMultiplier()
fn.score1=current.GetScore()
fn.sss=''
fn.aas=''
fn.num1s=''
fn.num10s=''
fn.num100s=''
fn.ss={}
fn.aa={}
fn.note={}
fn.segscore1={}
fn.subscore={}
fn.score2=0 -- total of fn.segscore1 for all segments
fn.segscore2={} -- total of fn.subscore for all subscores
fn.score3=0 -- total of fn.subscore for all segments & subscores
-- same as total of fn.segscore2 for all segments
fn.subscoretot={} -- total of fn.subscore for all segments
for nn=1,#subscores do
fn.subscoretot[nn]=0
end -- for nn
for n=1,fn.rtot do
fn.ss[n]=structure.GetSecondaryStructure(n)
fn.aa[n]=structure.GetAminoAcid(n)
fn.note[n]=structure.GetNote(n)
fn.segscore1[n]=current.GetSegmentEnergyScore(n)
fn.segscore2[n]=0
fn.score2=fn.score2+fn.segscore1[n]
fn.subscore[n]={}
for nn=1,#subscores do
fn.subscore[n][nn]=current.GetSegmentEnergySubscore(n,subscores[nn])
fn.subscoretot[nn]=fn.subscoretot[nn]+fn.subscore[n][nn]
fn.segscore2[n]=fn.segscore2[n]+fn.subscore[n][nn]
end -- for nn
fn.score3=fn.score3+fn.segscore2[n]
fn.sss=fn.sss..fn.ss[n]
fn.aas=fn.aas..fn.aa[n]
num100s=math.floor(n/100)
num10s=math.floor((n-100*num100s)/10)
num1s=n-100*num100s-10*num10s
fn.num1s=fn.num1s..num1s
fn.num10s=fn.num10s..num10s
fn.num100s=fn.num100s..num100s
if num1s==0 and n<fn.rtot then
fn.sss=fn.sss..'|'
fn.aas=fn.aas..'|'
fn.num1s=fn.num1s..'|'
fn.num10s=fn.num10s..'|'
fn.num100s=fn.num100s..'|'
end -- if num1s
end -- for n
print(fn.nam..' structure has '..fn.rtot..' amino acids and '..fn.nbands..' bands:')
print(' ')
print(fn.num100s..'\n'..fn.num10s..'\n'..fn.num1s..'\n'..fn.aas..'\n'..fn.sss)
print(' ')
pflag=0
for n=1,fn.rtot do
if fn.note[n]~='' then
print('Note '..n..': '..fn.note[n])
pflag=1
end
end -- for n
if pflag==1 then print(' ') end
print('Exploration multiplier = '..fn.expmul..'.')
print('Total score 1,2 = '..fn.score1..', '..fn.score2..' (differ by '..(fn.score1-fn.score2)..').')
print('Total score 1,3 = '..fn.score1..', '..fn.score3..' (differ by '..(fn.score1-fn.score3)..').')
print('Total score 2,3 = '..fn.score2..', '..fn.score3..' (differ by '..(fn.score2-fn.score3)..').')
for nn=1,#subscores do
if fn.subscoretot[nn]~=0 then
print('Total for '..subscores[nn]..' = '..fn.subscoretot[nn]..'.')
end
end -- for nn
print(' ')
for n=1,fn.rtot do
print('Segment '..fn.aa[n]..n..' has ss '..fn.ss[n]..' and the subscores below:')
for nn=1,#subscores do
if fn.subscore[n][nn]~=0 then
print(' '..subscores[nn]..' = '..fn.subscore[n][nn]..'.')
end
end -- for nn
print('Segment '..fn.aa[n]..n..' has score '..fn.segscore1[n]..' = '..fn.segscore2[n]..' (differ by '..(fn.segscore1[n]-fn.segscore2[n])..').')
if n<fn.rtot then
print(' ')
end -- if n
end -- for n
return fn
end -- ReadPrintStruct()
function is_int(res)
local val,tmp
tmp=string.gsub(res,'[%d]+','1')
-- print('res=\''..res..'\' gives tmp=\''..tmp..'\'')
if tmp=='1' then
val=true
else
val=false
end
return val
end -- is_int()
Main()