def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: # Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Create our first round _round_one = Round.Round(self.app, gender, "round_1") _round_one.set_cap(round_cap) # Create our first round data rand_players = random.sample(players[gender], len(players[gender])) for i in range(len(rand_players) // 2): # Grab our versus players p_one = rand_players[i * 2] p_two = rand_players[(i * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match #round_data[gender].append({ p_one.name(): p_one_score, p_two.name(): p_two_score }) #round_data[round_name][gender].append(Match.Match(round_name, p_one, p_two, p_one_score, p_two_score)) _round_one.add_match(Match.Match(_round_one, p_one, p_two, p_one_score, p_two_score)) # Append our first round to our season season.add_round(gender, _round_one) # Get the winners from each round for r in range(2, season.settings()['round_count'] + 1): # Define variables round_name = "round_"+str(r) # Define our Round _round = Round.Round(self.app, gender, round_name) # Items in Round print(_round.match_count()) # Debug if(self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format(season.name(), season.settings()['round_count']))
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: for r in range(0, season.settings()["round_count"]): # Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Define Round Variables r_id = (r + 1) r_name = "round_" + str(r_id) _r = Round.Round(self.app, gender, r_name) # Data to Check prev_r = season.round(gender, "round_" + str(r)) # Check if we have a round to take data from rnd_players = [ ] if(prev_r == None): rnd_players = random.sample(players[gender], len(players[gender])) else: rnd_players = random.sample(prev_r.winners(), len(prev_r.winners())) # Generate our matches from the data we have for w in range(len(rnd_players) // 2): # Define our players p_one = rnd_players[w * 2] p_two = rnd_players[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Add the match _r.add_match(Match.Match(_r, p_one, p_two, p_one_score, p_two_score)) # Add our round to our season season.add_round(gender, _r) # Debug if(self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format(season.name(), season.settings()['round_count']))
def set_rounds(self): for rnd in self._rounds_raw: for gdr in self._rounds_raw[rnd]: # If the Gender category doesn't exist within the rounds, create it if (not gdr in self._rounds): self._rounds[gdr] = [] # Populate our dictionary with our match data for match in self._rounds_raw[rnd][gdr]: Round = Round.Round() self._rounds[gdr].append(match)
def get_rounds(): sql = """ Select Round_Id, Round_Active, Round_StartTimeUTC, Round_Initiator From tb_Rounds r Order By Round_Id """ round_db_rows = db_return_rows(sql) round_list = [] for row in round_db_rows: round_list.append( Round(row["Round_Id"], row["Round_Active"], row["Round_StartTimeUTC"], row["Round_Initiator"])) return round_list
def get_round_by_id(round_id): sql_query = """ Select Round_Id, Round_Active, Round_StartTimeUTC, Round_Initiator From tb_Rounds Where Round_Id = %s """ parameters = (round_id) #should only return one row round_db_row = db_return_rows(sql_query, parameters) round_to_return = None for row in round_db_row: round_to_return = Round(row["Round_Id"], row["Round_Active"], row["Round_StartTimeUTC"], row["Round_Initiator"]) return round_to_return
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: for r in range(0, season.settings()["round_count"]): # Define Round Variables r_id = (r + 1) r_name = "round_" + str(r_id) _r = Round.Round(self.app, gender, r_name) # Data to Check prev_r = season.round(gender, "round_" + str(r)) # Check if we have a round to take data from if (prev_r == None): print("no data from round_" + str(r)) else: print("data found") #TODO: remove break break """# Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Create our first round _round_one = Round.Round(self.app, gender, "round_1") _round_one.set_cap(round_cap) # Create our first round data rand_players = random.sample(players[gender], len(players[gender])) for i in range(len(rand_players) // 2): # Grab our versus players p_one = rand_players[i * 2] p_two = rand_players[(i * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match _round_one.add_match(Match.Match(_round_one, p_one, p_two, p_one_score, p_two_score)) # Append our first round to our season season.add_round(gender, _round_one) # Get the winners from each round for r in range(2, season.settings()['round_count'] + 1): # Define variables round_name = "round_"+str(r) # Define our Round _round = Round.Round(self.app, gender, round_name) # Get our winners from the previous Round prev_round_name = "round_"+str(r-1) _prev_round = season.round(gender, prev_round_name) _winners = _prev_round.winners() for w in range(len(_winners) // 2): # Grab our versus players p_one = _winners[w * 2] p_two = _winners[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match _round.add_match(Match.Match(_round, p_one, p_two, p_one_score, p_two_score)) # Add our round to the season season.add_round(gender, _round)""" # Debug if (self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format( season.name(), season.settings()['round_count']))
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Our Round Data should be completely empty round_data = {} # Generate our rounds for gender in players: # Default Values round_name = "round_1" round_cap = 3 # Create our gendered rounds if (not gender in round_data): # Do we have a Round Cap overrider for this gender? if (gender + "_cap" in season.settings()): roundCap = season.settings()[gender + "_cap"] # Update our round data round_data.update({round_name: {gender: []}}) # Create our first round data from players _round_one = Round.Round(round_name, ) rand_players = random.sample(players[gender], len(players[gender])) for i in range(len(rand_players) // 2): # Grab our versus players p_one = rand_players[i * 2] p_two = rand_players[(i * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if (who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match #round_data[gender].append({ p_one.name(): p_one_score, p_two.name(): p_two_score }) round_data[round_name][gender].append( Match.Match(round_name, p_one, p_two, p_one_score, p_two_score)) # Append our first round to our season season.add_round(_round_one) # Get the winners from each round for r in range(1, season.settings()['round_count']): winners = season.round(r).winners() rand_players = random.sample(winners, len(winners)) for winner in range(rand_players): print("debug", winner) # Set our Round Data to our season season.set_rounds_raw(round_data) # Debug if (self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format( season.name(), season.settings()['round_count'])) print(len(season.rounds()["male"])) for match in season.rounds()["male"]: print(match.versuses(), match.round())
def generate_round(self, seasonId, tournamentName, roundId, genderName): # Get our Season Object season = self.get_season(seasonId) players = season.players() # Ensure we have a valid Season object if(season == None): return print("Invalid Season ID: {}".format(seasonId)) # Get our Tournament Object tournament = season.tournament(tournamentName) # Ensure we have a valid Tournament object if(tournament == None): return print("Invalid Tournament Name: {}".format(tournamentName)) # Ensure we have valid round data previous_round = tournament.round(genderName, "round_{}".format(roundId - 1)) if(previous_round == None and not (roundId - 1) == 0): return print("You can only generate this round when the rounds before Round {0} for {1}, {2} have been generated or manually inputed.".format(roundId, genderName.title(), tournamentName)) # Start Generation of Round if(previous_round == None): rand_players = random.sample(players[genderName], len(players[genderName])) else: rand_players = random.sample(previous_round.winners(), len(previous_round.winners())) # Check if this round has some data this_round = tournament.round(genderName, "round_{}".format(roundId)) if(this_round != None): # Clean up our rand_players array with matches that may exist for p in this_round.players(): if(p in rand_players): del rand_players[rand_players.index(p)] # Check if we have a round to take data from match_cap = (len(rand_players) // 2) if (previous_round == None) else (len(previous_round.winners()) // 2) # Generate our matches from the data we have round_cap = 3 if(genderName + "_cap" in season.settings()): round_cap = season.settings()[genderName + "_cap"] # Check if our round already exists _r = None if(this_round == None): _r = Round.Round(self.app, genderName, "round_{0}".format(roundId), tournament, match_cap) else: _r = this_round # Set our round attributes _r.set_previous_round(previous_round) _r.set_cap(round_cap) for w in range(len(rand_players) // 2): # Define our players p_one = rand_players[w * 2] p_two = rand_players[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Add the match _r.add_match(Match.Match(_r, p_one, p_two, p_one_score, p_two_score)) # Add our round to the tournament tournament.add_round(genderName, _r) # Save Data self.handle_save_rounds(tournament) return True
def input_round(self, seasonId, tournamentName, roundId, genderName): # Get our Season Object season = self.get_season(seasonId) players = None # Get our Tournament Object tournament = season.tournament(tournamentName) # Ensure we have a valid Tournament object if(tournament == None): return print("Invalid Tournament Name: {}".format(tournamentName)) # Ensure we have valid round data previous_round = tournament.round(genderName, "round_{}".format(roundId - 1)) if(previous_round == None and not (roundId - 1) == 0): return print("You can only generate this round when the rounds before Round {0} for {1}, {2} have been generated or manually inputed.".format(roundId, genderName.title(), tournamentName)) # Get the available players for this particular Round if(previous_round == None): players = season.players()[genderName] else: players = previous_round.winners() # Lets loop until all of our players have been used up available_players = players.copy() # Check if this round has some data this_round = tournament.round(genderName, "round_{}".format(roundId)) if(this_round != None): # Clean up our available_players array with matches that may exist for p in this_round.players(): if(p in available_players): del available_players[available_players.index(p)] # Get our input try: tryAgain = False tryAgainError = "" # Get our caps match_cap = (len(available_players) // 2) if (previous_round == None) else (len(previous_round.winners()) // 2) # Round Cap round_cap = 3 if(genderName + "_cap" in season.settings()): round_cap = season.settings()[genderName + "_cap"] # Check if our round already exists _r = None if(this_round == None): _r = Round.Round(self.app, genderName, "round_{0}".format(roundId), tournament, match_cap) else: _r = this_round # Update Round details _r.set_previous_round(previous_round) _r.set_cap(round_cap) # Add our round to the tournament tournament.add_round(genderName, _r) while(len(available_players) != 0): # Clear the Terminal call("cls") # Print out our available players print("Available Players for input on Round {0}:\n{1}".format(roundId, ", ".join([ p.name() for p in available_players ]))) # Handle Error if(tryAgain): print("\nError:\n{0}\n".format(tryAgainError)) tryAgain = False # Match Specific Variables winnerCount = 0 plyr_one = input("Please enter Player A: ") if(plyr_one in [ p.name() for p in available_players ]): plyr_one_score = input("Please enter the score for Player A: ") if(plyr_one_score.isdigit() and int(plyr_one_score) <= _r.cap()): # Type Conversion plyr_one_score = int(plyr_one_score) # Increment our Winner Count if(plyr_one_score == _r.cap()): winnerCount += 1 # Player B plyr_two = input("Please enter Player B: ") if(plyr_two in [ p.name() for p in available_players ] and plyr_two != plyr_one): plyr_two_score = input("Please enter the score for Player B: ") if(plyr_two_score.isdigit() and int(plyr_two_score) <= _r.cap()): # Type Conversion plyr_two_score = int(plyr_two_score) # Increment our Winner Count if(plyr_two_score == _r.cap()): winnerCount += 1 # Ensure we have one winner if(winnerCount == 1): # Get Player Objects p_one = next(( p for p in available_players if(p.name() == plyr_one)), None) p_two = next(( p for p in available_players if(p.name() == plyr_two)), None) # Ensure our Player's exist if(p_one and p_two): # Add this Match to the Round _m = Match.Match(_r, p_one, p_two, plyr_one_score, plyr_two_score) _r.add_match(_m) # Pop our players from the array del available_players[available_players.index(p_one)] del available_players[available_players.index(p_two)] # Save this match straight away self.handle_save_rounds(tournament) # Hold User input("Match ({0}) successfully added. Press <Return> to continue...\n".format(_m.versuses(True))) else: # Try Again tryAgainError = "The Players seize to exist within the available player list." tryAgain = True else: # Try Again tryAgainError = "A winner was not elected for this Match." if (winnerCount == 0) else "Matches cannot be left as a draw - only one player can win." tryAgain = True else: # Try Again tryAgainError = "The score entered for Player B ({0}) is invalid.".format(plyr_two_score) tryAgain = True else: # Try Again tryAgainError = "The player you entered ({0}) does not exist.".format(plyr_two) if plyr_two != plyr_one else "Player B cannot be the same as Player A." tryAgain = True continue else: # Try Again tryAgainError = "The score entered for Player A ({0}) is invalid.".format(plyr_one_score) tryAgain = True continue else: # Try Again tryAgainError = "The player you entered ({0}) does not exist.".format(plyr_one) tryAgain = True continue # Finalise the save to our tournament self.handle_save_rounds(tournament) except KeyboardInterrupt: # Clear Terminal call("cls") # Show user what happens when they restart print("You have tried to exit the program using Ctrl + C whilst inputting matches.", "\n") print("If you load previous rounds in your next session, you will be able to continue") print("from where you left off from this session.") # Exit Program Builder._app.exit() except Exception as err: # Clear Terminal call("cls") # Show user error print("An unknown error has occured:\n{0}".format(err)) traceback.print_exc() # Exit Program Builder._app.exit() return True
def generate_rounds(self, seasonId, minRoundId, maxRoundId): # Write our new data to memory season = self.get_season(seasonId) players = season.players() # For each tournament, generate rounds for tournament_name in season.tournaments(): # Get our tournament object tournament = season.tournament(tournament_name) # Generate our rounds for gender in players: for r in range(0, season.settings()["{}_round_count".format(gender)]): # Define Round Variables r_name = "round_" + str(r + 1) # Make sure we're not generating over our requested generation amount if (r < minRoundId): continue elif (r >= maxRoundId): break else: pass # Default Values round_cap = 3 # Data to Check prev_r = tournament.round(gender, "round_" + str(r)) # Check if we have a round to take data from match_cap = (len(players[gender]) // 2) if (prev_r == None) else (len(prev_r.winners()) // 2) # Do we have a Round Cap overrider for this gender? round_cap = 3 if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] _r = Round.Round(self.app, gender, r_name, tournament, match_cap) _r.set_cap(round_cap) # Check if we have a round to take data from rnd_players = [ ] if(prev_r == None): rnd_players = random.sample(players[gender], len(players[gender])) else: rnd_players = random.sample(prev_r.winners(), len(prev_r.winners())) _r.set_previous_round(prev_r) # Generate our matches from the data we have for w in range(len(rnd_players) // 2): # Define our players p_one = rnd_players[w * 2] p_two = rnd_players[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Add the match _r.add_match(Match.Match(_r, p_one, p_two, p_one_score, p_two_score)) # Add our round to our season tournament.add_round(gender, _r) # Debug if(self.app.debug): print("{} --- Round Added: [{}]".format([ w.name() for w in _r.winners() ], r_name)) # Import our data into JSON format for saving reference for g in tournament.rounds(): for r_id, r in enumerate(tournament.rounds()[g], 1): # Make sure our round exists within the raw data if(not "round_{0}".format(r_id) in tournament._rounds_raw): tournament._rounds_raw.update({ "round_{0}".format(r_id): { } }) # Make sure our gender exists within the raw data if(not g in tournament._rounds_raw["round_{0}".format(r_id)]): tournament._rounds_raw["round_{0}".format(r_id)].update({ g: [ ] }) # Insert our data tournament._rounds_raw["round_{0}".format(r_id)][g] = [ { m.player_one()[0].name(): m.player_one()[1], m.player_two()[0].name(): m.player_two()[1] } for m in tournament.round(g, r).matches() ] # Save Tournament Rounds (if enabled) if(tournament.file_saving()): tournament.save_rounds() # Debug if(self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}', minRound: {2}, maxRound: {3}".format(season.name(), season.settings()['round_count'], minRoundId, maxRoundId))
def load_previous_rounds(self, seasonId): # Get our Season Object season = self.get_season(seasonId) players = season.players() raw_json = season._j_data # Check that we have tournament data if(not "tournaments" in raw_json): raise("There are no tournaments within 'seasons.json'") # Check if the season has previous round data (through raw JSON) for tournament_name in raw_json['tournaments']: # Get our Tournament Object tournament = season.tournament(tournament_name) r_error_found = False error_found = False prev_round = { } # Check our rounds stored within the JSON data if("rounds" in raw_json['tournaments'][tournament_name]): # Load data in for rnd in raw_json['tournaments'][tournament_name]['rounds']: r_path = raw_json['tournaments'][tournament_name]['rounds'][rnd] for gdr in r_path: # Check if we had a previous round if(gdr not in prev_round): prev_round.update({ gdr: None }) rg_path = r_path[gdr] # Check if we have a round to take data from match_cap = (len(players[gdr]) // 2) if (prev_round[gdr] == None) else (len(prev_round[gdr].winners()) // 2) # Create our Round round_cap = 3 if(gdr + "_cap" in season.settings()): round_cap = season.settings()[gdr + "_cap"] _r = Round.Round(self.app, gdr, rnd, tournament, match_cap) _r.set_previous_round(prev_round[gdr]) _r.set_cap(round_cap) tournament.add_round(gdr, _r) # Add our Matches for match in rg_path: plyr_one = None plyr_two = None for i, plyr in enumerate(match, 0): if(i == 0): plyr_one = [plyr, match[plyr]] elif(i == 1): plyr_two = [plyr, match[plyr]] else: break # Setup our Match _m = Match.Match(_r, season.player(gdr, plyr_one[0]), season.player(gdr, plyr_two[0]), plyr_one[1], plyr_two[1]) # Check if errors occurred, if they have - we want to update our file to fix these issues m_error = True if _m.validate() > 0 else False if(m_error): error_found = True # Add our Match and Players to our round _r.add_match(_m) # Check if errors occurred, if they have - we want to update our file to fix these issues r_error = True if _r.validate() > 0 else False if(r_error): r_error_found = True # Set our previous round if(gdr in prev_round): prev_round[gdr] = _r # If errors have occurred, update file with fixes if(error_found or r_error_found): self.handle_save_rounds(tournament) # Update Raw Rounds tournament.update_rounds_raw()
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: for r in range(0, season.settings()["round_count"]): # Define Round Variables r_id = (r + 1) r_name = "round_" + str(r_id) _r = Round.Round(self.app, gender, r_name) # Data to Check prev_r = season.round(gender, "round_" + str(r)) # Check if we have a round to take data from rnd_players = [ ] if(prev_r == None): print("no data from previous round, creating...") rnd_players = random.sample(players[gender], len(players[gender])) else: print("data found") rnd_players = random.sample(prev_r.winners(), len(prev_r.winners())) print("rnd_players", rnd_players) # Generate our matches from the data we have for w in range(len(rnd_players) // 2): # Define our players # Add our round to our season season.add_round(gender, _r) #TODO: remove break break """# Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Create our first round _round_one = Round.Round(self.app, gender, "round_1") _round_one.set_cap(round_cap) # Create our first round data rand_players = random.sample(players[gender], len(players[gender])) for i in range(len(rand_players) // 2): # Grab our versus players p_one = rand_players[i * 2] p_two = rand_players[(i * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match _round_one.add_match(Match.Match(_round_one, p_one, p_two, p_one_score, p_two_score)) # Append our first round to our season season.add_round(gender, _round_one) # Get the winners from each round for r in range(2, season.settings()['round_count'] + 1): # Define variables round_name = "round_"+str(r) # Define our Round _round = Round.Round(self.app, gender, round_name) # Get our winners from the previous Round prev_round_name = "round_"+str(r-1) _prev_round = season.round(gender, prev_round_name) _winners = _prev_round.winners() for w in range(len(_winners) // 2): # Grab our versus players p_one = _winners[w * 2] p_two = _winners[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match _round.add_match(Match.Match(_round, p_one, p_two, p_one_score, p_two_score)) # Add our round to the season season.add_round(gender, _round)""" # Debug if(self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format(season.name(), season.settings()['round_count'])) # End of generate_rounds() # Used to load prize money def load_prize_money(self): with open('./data/rankingPoints.json') as tData: data = json.load(tData) # Fallback on a non-existant occurrence if(self.player_count == None): self.player_count = 100 # Make our prize_money a dictionary if(self.prize_money == None): self.prize_money = { } # Set the prize money to the actual rank and points received self.prize_money = [ pts for pts in data for rank in data[pts] ] # We want to set the prize money for all indexes possible via the player self.prize_money += [ 0 ] * ( self.player_count - len(self.prize_money)) # Used to load players from all seasons into memory def load_players(self): # Set our player (in gender) count self.player_count = 0 with open('./data/players.json') as tData: data = json.load(tData) # Players are classed within Seasons for season in data: # If the season does not yet exist, ignore this input if(not season in self.get_seasons()): continue # Players are then stored within Gender classifications for gender in data[season]: if(not gender in self.get_season(season).players()): self.get_season(season).players()[gender] = [ ] # Append our player in the season, within the gender for player in data[season][gender]: #TODO: Change to using Player class self.get_season(season).add_player(player, gender) # Update our player count if(len(self.get_season(season).players()[gender]) > self.player_count): self.player_count = len(self.get_season(season).players()[gender]) def get_seasons(self): return self.seasons def get_season(self, season_id): if(season_id in self.seasons): return self.seasons[season_id] else: return None
def load_tournaments(self): for seasonId in self.seasons: # Get our Season Object season = self.get_season(seasonId) # Grab Tournaments from raw JSON data stored in the Season for tournament_name in season._j_data['tournaments']: tournament_json = season._j_data['tournaments'][tournament_name] # Create our Tournament tournament = Tournament.Tournament(tournament_name) tournament.set_prize_money([money for money in tournament_json if(not "_difficulty" in money)]) season.add_tournament(tourn # Generate our rounds from our player list from scratch def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: for r in range(0, season.settings()["round_count"]): # Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Define Round Variables r_id = (r + 1) r_name = "round_" + str(r_id) _r = Round.Round(self.app, gender, r_name) # Data to Check prev_r = season.round(gender, "round_" + str(r)) # Check if we have a round to take data from rnd_players = [ ] if(prev_r == None): rnd_players = random.sample(players[gender], len(players[gender])) else: rnd_players = random.sample(prev_r.winners(), len(prev_r.winners())) # Generate our matches from the data we have for w in range(len(rnd_players) // 2): # Define our players p_one = rnd_players[w * 2] p_two = rnd_players[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Add the match _r.add_match(Match.Match(_r, p_one, p_two, p_one_score, p_two_score)) # Add our round to our season season.add_round(gender, _r) # Debug if(self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format(season.name(), season.settings()['round_count'])) # End of generate_rounds() # Used to load prize money def load_prize_money(self): with open('./data/rankingPoints.json') as tData: data = json.load(tData) # Fallback on a non-existant occurrence if(self.player_count == None): self.player_count = 100 # Make our prize_money a dictionary if(self.prize_money == None): self.prize_money = { } # Set the prize money to the actual rank and points received self.prize_money = [ pts for pts in data for rank in data[pts] ] # We want to set the prize money for all indexes possible via the player self.prize_money += [ 0 ] * ( self.player_count - len(self.prize_money)) # Used to load players from all seasons into memory def load_players(self): # Set our player (in gender) count self.player_count = 0 with open('./data/players.json') as tData: data = json.load(tData) # Players are classed within Seasons for season in data: # If the season does not yet exist, ignore this input if(not season in self.get_seasons()): continue # Players are then stored within Gender classifications for gender in data[season]: if(not gender in self.get_season(season).players()): self.get_season(season).players()[gender] = [ ] # Append our player in the season, within the gender for player in data[season][gender]: #TODO: Change to using Player class self.get_season(season).add_player(player, gender) # Update our player count if(len(self.get_season(season).players()[gender]) > self.player_count): self.player_count = len(self.get_season(season).players()[gender]) def get_seasons(self): return self.seasons def get_season(self, season_id): if(season_id in self.seasons): return self.seasons[season_id] else: return None
def blackJackConsole(): playing = True while playing: dealer = Dealer() player = Player() player.selectStartingAmount() lap = True while player.money > 0 and lap == True: player.lost_round = False round = Round() dealer.resetCards() player.resetCards() player.makeABet() newLine() player.takeCards(round, num=2) dealer.takeCards(round) dealer.showCardsAndPoints() player.showCardsAndPoints() player.askForAnotherCard() while player.another_card: player.takeCards(round) dealer.showCardsAndPoints() player.showCardsAndPoints() player.another_card = False if player.points[0] > 21: player.lostBecauseToManyPoints() else: player.askForAnotherCard() newLine() if not player.lost_round: dealer.takeEndCards(round) dealer.showCardsAndPoints() player.showCardsAndPoints() if player.points[0] > dealer.points or dealer.points > 21: player.wins() elif player.points[0] < dealer.points: player.loses() elif player.points[0] == dealer.points: itsATie(player) if player.money > 0: lap = askForNewRound() if not lap: player.showEndResult() playing = False else: playing = lostRoundAskForNew() if player.starting_money != 0: print('\nThank you for playing. See you next time!') print('\nIcon made by "Flat Icon" from www.flaticon.com') input("Press Enter to exit..")