Advertisement
MainiacJoe

DCSS Character Selection Tool

Jan 15th, 2018
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.74 KB | None | 0 0
  1. '''
  2. This module creates character build recommendations for
  3. Dungeon Crawl Stone Soup that give the opportunity to
  4. win a new species, background, or god.
  5.  
  6. The user needs to edit the 'wonSpecies' and 'wonBackgrounds'
  7.    tuple at the top of the module.
  8.  
  9. The module outputs four character build combos.  The player
  10.    chooses one of these that strikes his fancy, and if the
  11.    game is won it will add a species, background, and/or
  12.    god to the player's winlist.
  13. The first has an unwon species and a recommended background
  14.    for that species, which may or may not have been won
  15.    already.
  16. The second has an unwon species and a recommended species
  17.    for that background, which may or may not have been won
  18.    already.
  19. The third is a recommended combination of won species and
  20.    won background.  The player ought to choose an unwon god
  21.    for this combo.
  22. The fourth is a random pairing of species and background
  23.    without regard for recommendations.  If both the species
  24.    and background have already been won, a new god ought to
  25.    be worshipped.
  26.    
  27. The module when run will output a certain number of sets of
  28.    four combos, with a certain number of empty circles.  These
  29.    latter are to indicate a number of attempts for the chosen
  30.    combo of the four before moving on to the next line.  The
  31.    output can be cut and pasted into a word processor to be
  32.    printed.
  33. '''
  34.  
  35. from random import choice
  36.  
  37. ##############################
  38. ##  USER: EDIT THESE LINES  ##
  39. ##############################
  40.  
  41. ## Edit these tuples to reflect the species and backgrounds you've already won
  42.  
  43. wonSpecies = ('Ce','DD','Dg','Ds','Dr','Gr','Gh','Ha','HO','Ko','Mf','Mi',
  44.                'Sp','Tr','Vp','VS')
  45.  
  46. wonBackgrounds = ('Fi','Gl','Mo','Hu','As','Be','AK','En','Cj','FE','IE','EE',
  47.                    'Ar')
  48.  
  49. ## Edit these values to set the number of lines to be printed, and the number
  50. ##    of attempts for each line.
  51.  
  52. lines = 80
  53. attempts = 5
  54.  
  55. ###################
  56. ##  CODE BEGINS  ##
  57. ###################
  58.  
  59. ## These recommendations were harvested from the
  60. ##    character selection screen of 0.21.
  61.  
  62. speciesRecs = {'Hu':('Be','Cj','Ne','FE','IE'),
  63.                'Ba':('Fi','Be','Sk','Su','IE'),
  64.                'Ce':('Fi','Gl','Hu','Wr','AM'),
  65.                'DD':('Fi','Hu','Be','Ne','EE'),
  66.                'DE':('Wz','Cj','Su','Ne','FE','IE','AE','EE','VM'),
  67.                'Dg':('Tm','Cj','FE','IE','AE','EE'),
  68.                'Ds':('Gl','Be','AK','Wz','Ne','FE','IE','VM'),
  69.                'Dr':('Be','Tm','Cj','FE','IE','AE','EE','VM'),
  70.                'Fe':('Be','Tm','En','Cj','Su','IE','AE','VM'),
  71.                'Fo':('Fi','Hu','AK','AM','EE','VM'),
  72.                'Gr':('Fi','Gl','Mo','Be','FE','IE','EE','VM'),
  73.                'Gh':('Gl','Mo','Wr','Ne','IE','EE'),
  74.                'Ha':('Fi','Hu','Be','AK','Sk'),
  75.                'HO':('Fi','Mo','Be','AK','Ne','FE'),
  76.                'Ko':('Hu','Be','AM','En','Cj','Su'),
  77.                'Mf':('Gl','Be','Sk','Tm','Su','IE','VM'),
  78.                'Mi':('Fi','Gl','Mo','Hu','Be','AK'),              
  79.                'Mu':('Wz','Cj','Su','Ne','FE','IE'),
  80.                'Na':('Be','Tm','Wr','En','Wz','FE','IE','VM'),
  81.                'Op':('As','Tm','Wz','Cj','FE','IE','EE','VM'),
  82.                'Og':('Hu','Be','AM','Wz','FE'),
  83.                'Sp':('As','AK','Wr','En','Cj','EE','VM','Ar'),
  84.                'Te':('Be','Wz','Cj','Su','FE','AE','VM'),
  85.                'Tr':('Fi','Mo','Hu','Be','Wr','Wz','EE'),
  86.                'Vp':('Gl','As','En','Ne','IE','EE'),
  87.                'VS':('Fi','As','Be','En','Cj','Ne','IE')}
  88.  
  89. backgroundRecs = {'Fi':('HO','Mi','Gr','Tr','Ce','DD'),
  90.                   'Gl':('HO','Mi','Mf','Gr','Ce','DD'),
  91.                   'Mo':('HO','Mf','Gr','Tr','Ds','Ce','DD'),
  92.                   'Hu':('HO','Ha','Tr','Ko','Ce','Og'),
  93.                   'As':('Ha','Tr','Ds','Sp','VS','Vp'),
  94.                   'Be':('HO','Mi','Mf','Gr','Ha','Ds','Og'),
  95.                   'AK':('HO','Mf','Dr','Tr','Ds','Sp'),
  96.                   'CK':('HO','Mi','Mf','Dr','Tr','Ds','Ce'),
  97.                   'Sk':('Mf','Dr','Ha','Ce','Vp'),
  98.                   'Tm':('Mf','Dr','Tr','Ds','Dg','Na'),
  99.                   'Wr':('Dr','Ha','Ce','Sp','DD','Fe'),
  100.                   'AM':('Tr','Ko','Ce','Sp','DE','Fo'),
  101.                   'En':('Ko','Sp','DE','Vp','Na','Fe'),
  102.                   'Wz':('Dr','Hu','DE','Na','Op','Mu'),
  103.                   'Cj':('Dr','Te','DE','Dg','Na'),
  104.                   'Su':('HO','Mf','Te','DE','VS','Vp'),
  105.                   'Ne':('HO','Ds','DE','DD','Vp','Mu'),
  106.                   'FE':('HO','Gr','Te','DE','Dg','Na'),
  107.                   'IE':('Mf','Gr','Dr','DE','Dg','Na'),
  108.                   'AE':('Dr','Te','DE','VS','Na'),
  109.                   'EE':('Gr','Gh','Sp','DE','DD','Dg','Op'),
  110.                   'VM':('Mf','Ds','Sp','Te','DE','Na','Fe'),
  111.                   'Ar':('Dr','Ha','Ko','Ds','Sp','DD'),
  112.                   'Wn':('HO','Mf','Dr','Hu','Ds','Ce','Sp')}
  113.  
  114.  
  115.  
  116. ## Calculate which species and backgrounds still need to be won
  117.  
  118. allSpecies = speciesRecs.keys()
  119. allBackgrounds = backgroundRecs.keys()
  120.  
  121. needSpecies = [x for x in allSpecies if x not in wonSpecies]
  122. needBackgrounds = [x for x in allBackgrounds if x not in wonBackgrounds]
  123.  
  124.  
  125.  
  126. ## Validate each combo.
  127. ## Reject forbidden combos: DgBe, DgAK, DgCK, GhTm, MuTm
  128. ## If both the species and background have been won, the player needs to
  129. ##    be able to worship an unwon god.  This means that the species cannot
  130. ##    be Dg, and that the already-won background cannot be a zealot.  
  131.  
  132. species = lambda combo: combo[:2]
  133. background = lambda combo: combo[-2:]
  134.  
  135. def okay(combo):
  136.     if combo in ('DgBe','DgAK','DgCK','GhTm','MuTm'):
  137.         return False
  138.     s = species(combo)
  139.     b = background(combo)
  140.     if s in wonSpecies and b in wonBackgrounds:
  141.         if s == 'Dg' or b in ('Be','AK','CK'):
  142.             return False
  143.     return True
  144.  
  145.  
  146.  
  147. ## Select a combo with an unwon species
  148.  
  149. def newSpecies():
  150.     while True:
  151.         s = choice(needSpecies)
  152.         b = choice(speciesRecs[s])
  153.         combo = s + b
  154.         if okay(combo):
  155.             return combo
  156.  
  157.  
  158. ## Select a combo with an unwon background
  159.        
  160. def newBackground():
  161.     while True:
  162.         b = choice(needBackgrounds)
  163.         s = choice(backgroundRecs[b])
  164.         combo = s + b
  165.         if okay(combo):
  166.             return combo
  167.  
  168.  
  169. ## Select a combo that has a won species and a won background
  170.        
  171. ## use a set to handle duplicates from reciprocal recommendations
  172. doneCombos = set()
  173.  
  174. for s in wonSpecies:
  175.     for b in [x for x in wonBackgrounds if x in speciesRecs[s]]:
  176.         combo = s + b
  177.         if okay(combo):
  178.             doneCombos.add(combo)
  179.  
  180. for b in wonBackgrounds:
  181.     for s in [x for x in wonSpecies if x in backgroundRecs[b]]:
  182.         combo = s + b
  183.         if okay(combo):
  184.             doneCombos.add(combo)
  185.  
  186. ## random.choice will need to be able to index the group
  187. doneCombos = list(doneCombos)
  188.  
  189. def doneCombo():
  190.     return choice(doneCombos)
  191.  
  192.  
  193. ## Select a random combo
  194. def randomCombo():
  195.     while True:
  196.         s = choice(allSpecies)
  197.         b = choice(allBackgrounds)
  198.         combo = s + b
  199.         if okay(combo):
  200.             return combo
  201.  
  202.  
  203. ## Print a single line of combos.
  204. ## Make sure that each species and background in the line is unique
  205. def oneline(m):
  206.     circle = u'\u25ef'
  207.     while True:
  208.         line = [newSpecies(), newBackground(), doneCombo(),randomCombo()]
  209.         if (len(set([species(x) for x in line])) == 4 and
  210.             len(set([background(x) for x in line])) == 4):
  211.             break
  212.     line.extend([circle]*m)
  213.     print ' '.join(line)
  214.  
  215.  
  216. ## Print all the lines
  217. def alllines(n,m):
  218.     for i in range(n):
  219.         oneline(m)
  220.  
  221.  
  222. if __name__ == '__main__':
  223.     alllines(lines,attempts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement