Skip to content

Commit

Permalink
partial code for randomly selecting active expansions for play
Browse files Browse the repository at this point in the history
  • Loading branch information
privong authored and George C. Privon committed May 27, 2019
1 parent fb18b82 commit 6dc07d3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CarcassonneScore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
34 changes: 34 additions & 0 deletions cgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,40 @@ def getExpansions(self):
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.
Expand Down

0 comments on commit 6dc07d3

Please sign in to comment.