Update gauntlets.py

Restructure gauntlet draft to card slots
This commit is contained in:
Cal Corum 2023-04-27 14:40:32 -05:00
parent 6cf8782e23
commit 437bbb5522

View File

@ -296,11 +296,12 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra
mario_round = None mario_round = None
while round_num <= 26 and counter < 50: while round_num <= 26 and counter < 50:
counter += 1 counter += 1
# Set params based on current round
params = copy.deepcopy(base_params) params = copy.deepcopy(base_params)
# Set rarity param based on round number
if round_num == 1: if round_num == 1:
params.extend([ params.extend([
('min_rarity', RARITY['MVP']), ('max_rarity', RARITY['MVP']), ('pos_exc', 'RP') ('min_rarity', RARITY['MVP']), ('max_rarity', RARITY['MVP'])
]) ])
elif round_num == 2: elif round_num == 2:
params.extend([ params.extend([
@ -369,77 +370,103 @@ async def run_draft(interaction: discord.Interaction, main_team, this_event, dra
('min_rarity', RARITY['Replacement']), ('max_rarity', RARITY['Replacement']) ('min_rarity', RARITY['Replacement']), ('max_rarity', RARITY['Replacement'])
]) ])
# Any positional adjustments can be added as params here this_batch = []
for x in ['C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF']: for x in ['SP', 'RP', 'IF', 'OF']:
if counts[x] > 2 and 0 in [ # Slot 1 - SP
counts['C'], counts['1B'], counts['2B'], counts['3B'], counts['SS'], counts['LF'], if x == 'SP':
counts['CF'], counts['RF']]: if counts['SP'] < 6:
logging.info(f'0 exists in other positions; excluding {x}') slot_params = [('pos_inc', 'SP')]
params.append(('pos_exc', x)) elif counts['RP'] < 6:
elif x == 'C' and counts[x] > 2: slot_params = [('pos_inc', 'RP')]
params.append(('pos_exc', x)) else:
elif x in ['1B', '2B', '3B', 'SS'] and counts[x] > 3: slot_params = [('pos_exc', 'SP'), ('pos_exc', 'RP')]
params.append(('pos_exc', x))
elif x in ['LF', 'CF', 'RF'] and counts[x] > 4:
params.append(('pos_exc', x))
if round_num > 20 and counts[x] < 2:
params.append(('pos_inc', x))
if counts['RP'] > 7: # Slot 2 - RP
params.append(('pos_exc', 'RP')) elif x == 'RP':
if counts['SP'] > 4: logging.info(f'counts[RP]: {counts["RP"]}')
params.append(('pos_exc', 'SP')) if counts['RP'] < 8:
if counts['RP'] > counts['SP'] + 3: slot_params = [('pos_inc', 'RP')]
params.append(('pos_exc', 'RP')) elif counts['SP'] < 4:
if counts['SP'] > counts['RP'] + 3: slot_params = [('pos_inc', 'SP')]
params.append(('pos_exc', 'SP')) else:
if round_num > 20: slot_params = [('pos_exc', 'SP'), ('pos_exc', 'RP')]
if counts['SP'] < 5:
params.append(('pos_inc', 'SP'))
if counts['RP'] < 5:
params.append(('pos_inc', 'RP'))
# Call /players/random to get eight cards # Slot 3 - IF
p_query = None elif x == 'IF':
retries = 0 slot_params = []
while retries < 10: for y in ['1B', '2B', '3B', 'SS']:
try: if (counts[y] == 2 or counts[y] == 3) and 0 not in [
p_query = db_get('players/random', params=params) counts['C'], counts['1B'], counts['2B'], counts['3B'], counts['SS'], counts['LF'],
break counts['CF'], counts['RF']]:
except Exception as e: slot_params.append(('pos_inc', y))
retries += 1 elif counts[y] < 4:
slot_params.append(('pos_inc', y))
if counts['C'] < 2:
slot_params.append(('pos_inc', 'C'))
if len(slot_params) == 0:
slot_params = [('pos_exc', 'C'), ('pos_exc', '1B'), ('pos_exc', '2B'), ('pos_exc', '3B'),
('pos_exc', 'SS')]
if p_query['count'] > 0: # Slot 4 - OF
test_player_list = '' else:
for x in p_query['players']: slot_params = []
test_player_list += f'{x["rarity"]["name"]} - {x["description"]} - {helpers.get_all_pos(x)}\n' for y in ['LF', 'CF', 'RF']:
if counts[y] > 4:
pass
elif counts[y] > 2 and 0 not in [counts['LF'], counts['CF'], counts['RF']]:
slot_params.append(('pos_inc', y))
elif counts[y] < 3:
slot_params.append(('pos_inc', y))
if len(slot_params) == 0:
slot_params = [('pos_exc', 'LF'), ('pos_exc', 'CF'), ('pos_exc', 'RF')]
# Collect 4 cards with no repeat player names logging.info(f'this_batch: {this_batch}')
this_batch = [] logging.info(f'slot_params: {slot_params}')
for x in p_query['players']: logging.info(f'params: {params}')
if x['p_name'] not in p_names: slot_params.extend(params)
this_batch.append(x) p_query = db_get('players/random', params=slot_params)
if len(this_batch) == 4:
if p_query['count'] > 0:
# test_player_list = ''
# for z in p_query['players']:
# test_player_list += f'{z["rarity"]["name"]} - {z["description"]} - {helpers.get_all_pos(x)}\n'
# Collect 1 cards with no repeat player names
for i in p_query['players']:
if i['p_name'] not in p_names and i not in this_batch:
this_batch.append(i)
break break
# Present choices and capture selection if len(this_batch) < 4:
p_choice = await helpers.get_choice_from_cards(interaction, this_batch, delete_message=True) logging.error(f'Pulled less than 4 players in gauntlet draft')
p_query = db_get('players/random', params=params)
for i in p_query['players']:
if i['p_name'] not in p_names and i not in this_batch:
this_batch.append(i)
if len(this_batch) >= 4:
break
# Add player to list and update counts if len(this_batch) < 4:
p_names.append(p_choice['p_name']) raise KeyError(f'This is embarassing, but I couldn\'t find enough players for you to draft from.')
counts[p_choice['rarity']['name']] += 1
all_players.append(p_choice)
if p_choice['pos_1'] in ['SP', 'RP']: # Present choices and capture selection
counts[p_choice['pos_1']] += 1 p_choice = await helpers.get_choice_from_cards(interaction, this_batch, delete_message=True)
else:
for x in helpers.get_all_pos(p_choice):
if x in counts:
counts[x] += 1
# Update roster embed # Add player to list and update counts
round_num += 1 p_names.append(p_choice['p_name'])
await last_message.edit(content=None, embeds=get_embeds(include_links=False)) counts[p_choice['rarity']['name']] += 1
all_players.append(p_choice)
if p_choice['pos_1'] in ['SP', 'RP']:
counts[p_choice['pos_1']] += 1
else:
for x in helpers.get_all_pos(p_choice):
if x in counts:
counts[x] += 1
# Update roster embed
round_num += 1
await last_message.edit(content=None, embeds=get_embeds(include_links=False))
else: else:
logging.error(f'run_draft - No draft logic for Event ID {this_event["id"]}') logging.error(f'run_draft - No draft logic for Event ID {this_event["id"]}')
raise KeyError(f'Draft data not found for Gauntlet {this_event["id"]}') raise KeyError(f'Draft data not found for Gauntlet {this_event["id"]}')