SHARE
TWEET

CG303 Score Part All V3.01

Crashguard303 Oct 12th, 2012 33 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. Score Part all by Crashguard303
  3. 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.
  4. Over the selected segment-range, a score sum for each single score part is calculated and the overall-sum of all selected score parts.
  5. Results are shown in the script recipe output window.
  6. If you select all segments (1 as first and maximum as last) in sliders,
  7. and check all score parts, the overall score sum should be 8000 points fewer than puzzle score (in most puzzles).
  8. ]]--
  9. function DialogCheck()
  10.  -- create dialog containing checkboxes with names as in ScorePartNames
  11.  
  12.  local ask -- initialize table ask for dialog display and storing chekbox values
  13.  ask = dialog.CreateDialog("Get all score parts") -- windows title
  14.  
  15.  ask.which_segments = dialog.AddLabel("Which segment range?") -- add label for information
  16.  ask.first = dialog.AddSlider("first segment",1,1,NumSegs,0)
  17.  -- add slider for first segment to calculate. initial value is 1, range is 1...number of segments, stepsize is 10^0=1
  18.  -- slider method parameters: (name,initial value,min,max,10^-stepsize (0 is 1, 1 is .1, 10 is .01 etc)
  19.  ask.last = dialog.AddSlider("last segment",NumSegs,1,NumSegs,0)
  20.  -- add slider for last segment to calculate. initial value is number of segments, range is 1...number of segments, stepsize is 10^0=1
  21.  
  22.  ask.which_parts = dialog.AddLabel("\nWhich score parts?") -- add label for information
  23.  local k
  24.  for k=1,#ScorePartNames do -- by variable k, cycle through all score part names
  25.   ask[ScorePartNames[k]] = dialog.AddCheckbox(ScorePartNames[k], false)
  26.   -- for each name, create a checkbox with this variable-name and show it as text
  27.   -- default value for aech checkbox is false
  28.  end -- k loop
  29.  
  30.  ask.OK = dialog.AddButton("OK", 1) -- add OK button returning 1 in function if pressed
  31.  ask.Cancel = dialog.AddButton("Cancel", 0) -- add cancel button retunrning 0 in function if pressed
  32.  
  33.  return ask,dialog.Show(ask)
  34.  -- return what is in table ask (containing which score parts (by names) have been selected) and flag for OK button
  35. end -- function
  36.  
  37. function ScoreCalculate(ScoreCheck)
  38. -- for all segments in range, calculate all score parts selected in ScoreCheck
  39.  
  40.  if ScoreCheck.first.value>ScoreCheck.last.value then
  41.  -- if first segment value is bigger than last segment value
  42.   ScoreCheck.first.value,ScoreCheck.last.value = ScoreCheck.last.value,ScoreCheck.first.value
  43.   -- swap values
  44.  end -- if ScoreCheck.first>ScoreCheck.last
  45.  
  46.  print("Calculating score parts from segment "..ScoreCheck.first.value.." to "..ScoreCheck.last.value)
  47.  
  48.  local ScorePart={} -- initialize table for score-part-segment-sums
  49.  ScorePart.all=0 -- in this table, initialize overall-sum value
  50.  
  51.  local k
  52.  for k=1,#ScorePartNames do -- by variable k, cycle through all score part names
  53.  
  54.   if ScoreCheck[ScorePartNames[k]].value then
  55.   -- if this score part name was checked in table ScoreCheck (ScoreCheck.ScorePartNames[k].value == true)
  56.   -- same as if ScoreCheck[ScorePartNames[k]]["value"] == true
  57.    ScorePart[ScorePartNames[k]]=0 -- initialize variable for score-part-segment-sum
  58.  
  59.    local l
  60.    for l=ScoreCheck.first.value,ScoreCheck.last.value do -- by variable l, cycle through all selected segments
  61.     ScorePart[ScorePartNames[k]]=ScorePart[ScorePartNames[k]]+absolutebest.GetSegmentEnergySubscore(l,ScorePartNames[k])
  62.     -- add score part with name ScorePartNames[k] at segment l to score-part-segment-sum
  63.    end -- l loop
  64.  
  65.    -- when all single segment-scores of one score-part-segment-sum have been added
  66.    ScorePart.all=ScorePart.all+ScorePart[ScorePartNames[k]]
  67.    -- add this score-part-segment-sum value to overall-sum, too
  68.  
  69.   end -- if ScoreCheck
  70.  
  71.  end -- k loop
  72.  
  73.  return ScorePart
  74.  -- return this value as function value
  75. end -- function
  76.  
  77. function ScoreShow(ScoreCheck,ScorePart)
  78. -- show all score parts with names, values and overall-sum
  79.  
  80.  local k
  81.  for k=1,#ScorePartNames do -- by variable k, cycle through all score part names
  82.  
  83.   if ScoreCheck[ScorePartNames[k]].value then
  84.   -- if this score part name was checked in table ScoreCheck (ScoreCheck.ScorePartNames[k].value == true)
  85.    print (ScorePartNames[k]..": "..ScorePart[ScorePartNames[k]]) -- show score-part name and segment sum
  86.   end -- if ScoreCheck
  87.  end-- k
  88.  print ("Sum of all parts: "..ScorePart.all)  -- show overall-sum
  89. end -- function
  90.  
  91. NumSegs=structure.GetCount() -- set variable NumSegs to number of all puzzle segments fetched by function
  92. ScorePartNames={"clashing";"packing";"hiding";"bonding";"backbone";"sidechain";"reference";"disulfides";"other"}
  93. -- initialize table containing all score part (criteria) names
  94.  
  95. local ScoreCheck={} -- initialize table containing information which score criteria should be checked, calculated and displayed
  96. local OKFlag -- initialize flag containing information if OK was pressed in score criteria selection dialog
  97.  
  98. ScoreCheck,OKFlag=DialogCheck()
  99. -- set ScoreCheck and OKFlag by calling score criteria selection dialog containing checkboxes with names as in ScorePartNames
  100.  
  101. local ScorePart={}
  102.  
  103. if OKFlag>0 then -- if OK was pressed
  104.  ScorePart=ScoreCalculate(ScoreCheck) -- by content of ScoreCheck, calculate scores
  105.  ScoreShow(ScoreCheck,ScorePart) -- and show them
  106. end -- if OKFlag
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top