Quellcode durchsuchen

partial code for randomly selecting active expansions for play

George C. Privon vor 6 Jahren
Ursprung
Commit
6dc07d359d
2 geänderte Dateien mit 37 neuen und 0 gelöschten Zeilen
  1. 3 0
      CarcassonneScore.py
  2. 34 0
      cgame.py

+ 3 - 0
CarcassonneScore.py

@@ -33,6 +33,9 @@ def getargs():
 system.")
     parser.add_argument('-c', '--config', default='CarcassonneScore.conf',
                         help='Location of the configuration file.')
+    parser.add_argument(('--random-exp', default=False,
+                         help="Select a random set of active expansions and \
+mini-expansions.")
 
     return parser.parse_args()
 

+ 34 - 0
cgame.py

@@ -256,6 +256,40 @@ class cgame:
         return 0
 
 
+    def getRandomExpansions(self):
+        """
+        Select a set of random expansions for play.
+        """
+        res = cur.execute('''SELECT DISTINCT expansionID FROM expansions WHERE active=1;''')
+
+        explist = res.fetchall()
+        explist = np.array([x[0] for x in explist])
+
+
+        exps = explist[explist < 100]
+        miniexps = explist[explist >= 100]
+
+        nexp = random.randint(0, len(exps))
+        nminiexp = random.randint(0, len(miniexps))
+
+        print("Selecting {0:d} full expansions and {1:d} mini expansions.".format(nexp,
+                                                                                  nminiexp))
+
+        if nexp:
+            selexp = sorted(random.sample(list(exps), nexp))
+            print("Full expansions: ", selexp)
+        else:
+            selexp = []
+
+        if nminiexp:
+            selminiexp = sorted(random.sample(list(miniexps), nminiexp))
+            print("Mini expansions: ", selminiexp)
+        else:
+            selminiexp = []
+
+        return selexp + selminiexp
+
+
     def getPlayerName(self, playerID):
         """
         Given a playerID, return a player's name from the database.