Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Score Part all by Crashguard303
- This script pops out an input-box dialog, where you can select a range of puzzle segments (by sliders) and check score parts (packing, hiding, clashing etc.) by checkboxes.
- Over the selected segment-range, a score sum for each single score part is calculated and the overall-sum of all selected score parts.
- Results are shown in the script recipe output window.
- If you select all segments (1 as first and maximum as last) in sliders,
- and check all score parts, the overall score sum should be 8000 points fewer than puzzle score (in most puzzles).
- ]]--
- function DialogCheck()
- -- create dialog containing checkboxes with names as in ScorePartNames
- local ask -- initialize table ask for dialog display and storing chekbox values
- ask = dialog.CreateDialog("Get all score parts") -- windows title
- ask.which_segments = dialog.AddLabel("Which segment range?") -- add label for information
- ask.first = dialog.AddSlider("first segment",1,1,NumSegs,0)
- -- add slider for first segment to calculate. initial value is 1, range is 1...number of segments, stepsize is 10^0=1
- -- slider method parameters: (name,initial value,min,max,10^-stepsize (0 is 1, 1 is .1, 10 is .01 etc)
- ask.last = dialog.AddSlider("last segment",NumSegs,1,NumSegs,0)
- -- add slider for last segment to calculate. initial value is number of segments, range is 1...number of segments, stepsize is 10^0=1
- ask.which_parts = dialog.AddLabel("\nWhich score parts?") -- add label for information
- local k
- for k=1,#ScorePartNames do -- by variable k, cycle through all score part names
- ask[ScorePartNames[k]] = dialog.AddCheckbox(ScorePartNames[k], false)
- -- for each name, create a checkbox with this variable-name and show it as text
- -- default value for aech checkbox is false
- end -- k loop
- ask.OK = dialog.AddButton("OK", 1) -- add OK button returning 1 in function if pressed
- ask.Cancel = dialog.AddButton("Cancel", 0) -- add cancel button retunrning 0 in function if pressed
- return ask,dialog.Show(ask)
- -- return what is in table ask (containing which score parts (by names) have been selected) and flag for OK button
- end -- function
- function ScoreCalculate(ScoreCheck)
- -- for all segments in range, calculate all score parts selected in ScoreCheck
- if ScoreCheck.first.value>ScoreCheck.last.value then
- -- if first segment value is bigger than last segment value
- ScoreCheck.first.value,ScoreCheck.last.value = ScoreCheck.last.value,ScoreCheck.first.value
- -- swap values
- end -- if ScoreCheck.first>ScoreCheck.last
- print("Calculating score parts from segment "..ScoreCheck.first.value.." to "..ScoreCheck.last.value)
- local ScorePart={} -- initialize table for score-part-segment-sums
- ScorePart.all=0 -- in this table, initialize overall-sum value
- local k
- for k=1,#ScorePartNames do -- by variable k, cycle through all score part names
- if ScoreCheck[ScorePartNames[k]].value then
- -- if this score part name was checked in table ScoreCheck (ScoreCheck.ScorePartNames[k].value == true)
- -- same as if ScoreCheck[ScorePartNames[k]]["value"] == true
- ScorePart[ScorePartNames[k]]=0 -- initialize variable for score-part-segment-sum
- local l
- for l=ScoreCheck.first.value,ScoreCheck.last.value do -- by variable l, cycle through all selected segments
- ScorePart[ScorePartNames[k]]=ScorePart[ScorePartNames[k]]+absolutebest.GetSegmentEnergySubscore(l,ScorePartNames[k])
- -- add score part with name ScorePartNames[k] at segment l to score-part-segment-sum
- end -- l loop
- -- when all single segment-scores of one score-part-segment-sum have been added
- ScorePart.all=ScorePart.all+ScorePart[ScorePartNames[k]]
- -- add this score-part-segment-sum value to overall-sum, too
- end -- if ScoreCheck
- end -- k loop
- return ScorePart
- -- return this value as function value
- end -- function
- function ScoreShow(ScoreCheck,ScorePart)
- -- show all score parts with names, values and overall-sum
- local k
- for k=1,#ScorePartNames do -- by variable k, cycle through all score part names
- if ScoreCheck[ScorePartNames[k]].value then
- -- if this score part name was checked in table ScoreCheck (ScoreCheck.ScorePartNames[k].value == true)
- print (ScorePartNames[k]..": "..ScorePart[ScorePartNames[k]]) -- show score-part name and segment sum
- end -- if ScoreCheck
- end-- k
- print ("Sum of all parts: "..ScorePart.all) -- show overall-sum
- end -- function
- NumSegs=structure.GetCount() -- set variable NumSegs to number of all puzzle segments fetched by function
- ScorePartNames={"clashing";"packing";"hiding";"bonding";"backbone";"sidechain";"reference";"disulfides";"other"}
- -- initialize table containing all score part (criteria) names
- local ScoreCheck={} -- initialize table containing information which score criteria should be checked, calculated and displayed
- local OKFlag -- initialize flag containing information if OK was pressed in score criteria selection dialog
- ScoreCheck,OKFlag=DialogCheck()
- -- set ScoreCheck and OKFlag by calling score criteria selection dialog containing checkboxes with names as in ScorePartNames
- local ScorePart={}
- if OKFlag>0 then -- if OK was pressed
- ScorePart=ScoreCalculate(ScoreCheck) -- by content of ScoreCheck, calculate scores
- ScoreShow(ScoreCheck,ScorePart) -- and show them
- end -- if OKFlag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement