Browse Source

Merge branch 'master' into main

George C. Privon 5 năm trước cách đây
mục cha
commit
7edbd6a6ab
3 tập tin đã thay đổi với 59 bổ sung9 xóa
  1. 6 0
      CHANGELOG.md
  2. 6 3
      CarcassonneScore.py
  3. 47 6
      cgame.py

+ 6 - 0
CHANGELOG.md

@@ -2,6 +2,12 @@
 
 ## 0.4 Series
 
+### 0.4.4 (07 December 2020)
+
+#### Enhancements
+
+* Note when a score has not been recorded.
+
 ### 0.4.3 (22 May 2019)
 
 #### Enhancements

+ 6 - 3
CarcassonneScore.py

@@ -2,7 +2,7 @@
 """
 Carcassonne score keeping system.
 
-Copyright 2018 George C. Privon
+Copyright 2018-2019 George C. Privon
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@ import argparse
 import sys
 import cgame
 
-__version__ = "0.4.2"
+__version__ = "0.4.4"
 
 def getargs():
     """
@@ -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()
 
@@ -44,7 +47,7 @@ def main():
 
     args = getargs()
 
-    mygame = cgame.cgame(config=args.config)
+    mygame = cgame.cgame(args=args)
 
     mygame.runGame()
 

+ 47 - 6
cgame.py

@@ -32,7 +32,7 @@ class cgame:
     Carcassonne game object
     """
 
-    def __init__(self, config='CarcassonneScore.db'):
+    def __init__(self, args=None):
         """
         Initialize some variables and set up a game
         """
@@ -44,7 +44,13 @@ class cgame:
                          ('q', 'quit (will be removed for real gameplay'),
                          ('?', 'print help')]
 
-        self.loadConfig(config)
+        if args is None:
+            _sys.stderr.write("Error: must provide a set of arguments when using the cgame class.\n")
+            _sys.stderr.write("Exiting.\n\n")
+            _sys.exit()
+        self.args = args
+
+        self.loadConfig()
 
         self.conn = _sqlite3.connect(self.config.get('CarcassonneScore', 'DBNAME'))
         self.cur = self.conn.cursor()
@@ -53,17 +59,17 @@ class cgame:
         self.setupGame()
 
 
-    def loadConfig(self, cfile):
+    def loadConfig(self):
         """
         Load configuration file
         """
 
-        if not _os.path.isfile(cfile):
-            _sys.stderr.write("Error: could not find configuration file '" + cfile + "'\n")
+        if not _os.path.isfile(self.args.config):
+            _sys.stderr.write("Error: could not find configuration file '" + self.args.config + "'\n")
             _sys.exit()
 
         self.config = _configparser.RawConfigParser()
-        self.config.read(cfile)
+        self.config.read(self.args.config)
 
         # set up a preferences dictionary
         self.preferences = {}
@@ -258,6 +264,40 @@ an option from the list.\n".format(playerID))
         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.
@@ -363,6 +403,7 @@ an option from the list.\n".format(playerID))
         _sys.stdout.write(' with ' + score['tokens'] + '.\n')
         answer = input("Is this correct? (y/n) ")
         if not _re.match('y', answer, _re.IGNORECASE):
+            _sys.stdout.write("Note: score not recorded.\n")
             return 1
 
         # now construct a SQL query