|
|
@@ -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
|