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
while round_num <= 26 and counter < 50:
counter += 1
# Set params based on current round
params = copy.deepcopy(base_params)
# Set rarity param based on round number
if round_num == 1:
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:
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'])
])
# Any positional adjustments can be added as params here
for x in ['C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF']:
if counts[x] > 2 and 0 in [
counts['C'], counts['1B'], counts['2B'], counts['3B'], counts['SS'], counts['LF'],
counts['CF'], counts['RF']]:
logging.info(f'0 exists in other positions; excluding {x}')
params.append(('pos_exc', x))
elif x == 'C' and counts[x] > 2:
params.append(('pos_exc', x))
elif x in ['1B', '2B', '3B', 'SS'] and counts[x] > 3:
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))
this_batch = []
for x in ['SP', 'RP', 'IF', 'OF']:
# Slot 1 - SP
if x == 'SP':
if counts['SP'] < 6:
slot_params = [('pos_inc', 'SP')]
elif counts['RP'] < 6:
slot_params = [('pos_inc', 'RP')]
else:
slot_params = [('pos_exc', 'SP'), ('pos_exc', 'RP')]
if counts['RP'] > 7:
params.append(('pos_exc', 'RP'))
if counts['SP'] > 4:
params.append(('pos_exc', 'SP'))
if counts['RP'] > counts['SP'] + 3:
params.append(('pos_exc', 'RP'))
if counts['SP'] > counts['RP'] + 3:
params.append(('pos_exc', 'SP'))
if round_num > 20:
if counts['SP'] < 5:
params.append(('pos_inc', 'SP'))
if counts['RP'] < 5:
params.append(('pos_inc', 'RP'))
# Slot 2 - RP
elif x == 'RP':
logging.info(f'counts[RP]: {counts["RP"]}')
if counts['RP'] < 8:
slot_params = [('pos_inc', 'RP')]
elif counts['SP'] < 4:
slot_params = [('pos_inc', 'SP')]
else:
slot_params = [('pos_exc', 'SP'), ('pos_exc', 'RP')]
# Call /players/random to get eight cards
p_query = None
retries = 0
while retries < 10:
try:
p_query = db_get('players/random', params=params)
break
except Exception as e:
retries += 1
# Slot 3 - IF
elif x == 'IF':
slot_params = []
for y in ['1B', '2B', '3B', 'SS']:
if (counts[y] == 2 or counts[y] == 3) and 0 not in [
counts['C'], counts['1B'], counts['2B'], counts['3B'], counts['SS'], counts['LF'],
counts['CF'], counts['RF']]:
slot_params.append(('pos_inc', y))
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:
test_player_list = ''
for x in p_query['players']:
test_player_list += f'{x["rarity"]["name"]} - {x["description"]} - {helpers.get_all_pos(x)}\n'
# Slot 4 - OF
else:
slot_params = []
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
this_batch = []
for x in p_query['players']:
if x['p_name'] not in p_names:
this_batch.append(x)
if len(this_batch) == 4:
logging.info(f'this_batch: {this_batch}')
logging.info(f'slot_params: {slot_params}')
logging.info(f'params: {params}')
slot_params.extend(params)
p_query = db_get('players/random', params=slot_params)
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
# Present choices and capture selection
p_choice = await helpers.get_choice_from_cards(interaction, this_batch, delete_message=True)
if len(this_batch) < 4:
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
p_names.append(p_choice['p_name'])
counts[p_choice['rarity']['name']] += 1
all_players.append(p_choice)
if len(this_batch) < 4:
raise KeyError(f'This is embarassing, but I couldn\'t find enough players for you to draft from.')
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
# Present choices and capture selection
p_choice = await helpers.get_choice_from_cards(interaction, this_batch, delete_message=True)
# Update roster embed
round_num += 1
await last_message.edit(content=None, embeds=get_embeds(include_links=False))
# Add player to list and update counts
p_names.append(p_choice['p_name'])
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:
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"]}')