Day 1 Updates

This commit is contained in:
Cal Corum 2023-10-24 09:48:46 -05:00
parent f68a8166e7
commit e0ef5616bd
5 changed files with 70 additions and 25 deletions

View File

@ -330,9 +330,9 @@ async def build_lineup(team_object: dict, game_id: int, league_name: str, sp_nam
lineups = [] lineups = []
i = 1 i = 1
for x in [grp_1, grp_2, grp_3]: for x in [grp_1, grp_2, grp_3]:
logging.info(f'group: {x}') logging.debug(f'group: {x}')
for y in x: for y in x:
logging.info(f'y: {y}') logging.debug(f'y: {y}')
card_id = await get_or_create_card(y[1]['player'], team_object) card_id = await get_or_create_card(y[1]['player'], team_object)
lineups.append({ lineups.append({
@ -467,7 +467,8 @@ async def get_relief_pitcher(this_play: StratPlay, ai_team: dict, league_name: s
need = 'length' need = 'length'
logging.debug(f'need: {need}') logging.debug(f'need: {need}')
rp_query = await db_get(f'teams/{ai_team["id"]}/rp/{league_name}?need={need}&used_pitcher_ids={id_string}') rp_query = await db_get(f'teams/{ai_team["id"]}/rp/{league_name.split("-run")[0]}'
f'?need={need}&used_pitcher_ids={id_string}')
card_id = await get_or_create_card(rp_query, ai_team) card_id = await get_or_create_card(rp_query, ai_team)
return { return {
'game_id': this_play.game.id, 'game_id': this_play.game.id,

View File

@ -459,7 +459,7 @@ class Gameplay(commands.Cog):
# AI Team is pitching # AI Team is pitching
if game_state['pitcher']['team']['is_ai']: if game_state['pitcher']['team']['is_ai']:
ai_data = await ai_manager.pitching_ai_note(game_state['curr_play'], game_state['pitcher']) ai_data = await ai_manager.pitching_ai_note(game_state['curr_play'], game_state['pitcher'])
logging.info(f'ai_data: {ai_data}') logging.debug(f'ai_data: {ai_data}')
ai_note = ai_data['note'] ai_note = ai_data['note']
gm_name = ai_data['gm_name'] gm_name = ai_data['gm_name']
embed.set_thumbnail(url=ai_data['pitcher']["image"]) embed.set_thumbnail(url=ai_data['pitcher']["image"])
@ -1227,7 +1227,7 @@ class Gameplay(commands.Cog):
return return
logging.debug(f'Setting lineup for {ai_team["sname"]} in PD game') logging.debug(f'Setting lineup for {ai_team["sname"]} in PD game')
logging.info(f'lineups: {all_lineups}') logging.debug(f'lineups: {all_lineups}')
post_lineups(all_lineups) post_lineups(all_lineups)
await interaction.channel.send( await interaction.channel.send(
@ -1422,7 +1422,7 @@ class Gameplay(commands.Cog):
@group_new_game.command(name='gauntlet', description='Start a new Gauntlet game against an AI') @group_new_game.command(name='gauntlet', description='Start a new Gauntlet game against an AI')
@commands.has_any_role(PD_PLAYERS_ROLE_NAME) @commands.has_any_role(PD_PLAYERS_ROLE_NAME)
async def new_game_gauntlet_command( async def new_game_gauntlet_command(
self, interaction: discord.Interaction, event_name: Literal['Taste of 2018']): self, interaction: discord.Interaction, event_name: Literal['Taste of 2018'], sp_card_id: int):
await interaction.response.defer() await interaction.response.defer()
conflict = get_one_game(channel_id=interaction.channel.id, active=True) conflict = get_one_game(channel_id=interaction.channel.id, active=True)
@ -1517,6 +1517,37 @@ class Gameplay(commands.Cog):
t_role = await team_role(interaction, main_team) t_role = await team_role(interaction, main_team)
all_lineups = [] all_lineups = []
# Get Human SP
human_sp_card = await db_get(f'cards', object_id=sp_card_id)
if human_sp_card['team']['id'] != team['id']:
logging.error(
f'Card_id {sp_card_id} does not belong to {team["abbrev"]} in Game {this_game.id}'
)
await interaction.channel.send(
f'Uh oh. Card ID {sp_card_id} is {team["player"]["p_name"]} and belongs to '
f'{human_sp_card["team"]["sname"]}. Will you double check that before we get started?')
return
if this_game.game_type in ['major-league', 'hall-of-fame']:
l_check = await legal_check([human_sp_card['id']])
if not l_check['legal']:
await interaction.edit_original_response(
content=f'It looks like this is a Ranked Legal game and {player_desc(human_sp_card["player"])} is '
f'not legal in Ranked. You can start a new game once you get a new SP.'
)
return
all_lineups.append({
'game_id': this_game.id,
'team_id': team['id'],
'player_id': human_sp_card['player']['player_id'],
'card_id': sp_card_id,
'position': 'P',
'batting_order': 10,
'after_play': 0
})
# Get AI Starting Pitcher # Get AI Starting Pitcher
try: try:
await interaction.edit_original_response( await interaction.edit_original_response(
@ -1653,15 +1684,26 @@ class Gameplay(commands.Cog):
return return
valid_end = False valid_end = False
logging.debug(f'latest play: {latest_play}')
if latest_play.starting_outs == 0: if latest_play.starting_outs == 0:
if latest_play.inning_half == 'top': logging.debug(f'no outs')
if latest_play.inning_half.lower() == 'top':
logging.debug(f'top of inning')
if latest_play.inning_num > 9 and latest_play.away_score != latest_play.home_score: if latest_play.inning_num > 9 and latest_play.away_score != latest_play.home_score:
logging.debug(f'after the ninth and not tied')
valid_end = True valid_end = True
if abs(latest_play.home_score - latest_play.away_score) >= 10: if abs(latest_play.home_score - latest_play.away_score) >= 10:
logging.debug(f'not after ninth, but mercy')
valid_end = True valid_end = True
elif latest_play.inning_half == 'bot' and abs(latest_play.home_score - latest_play.away_score) >= 10: if latest_play.inning_half.lower() == 'bot':
valid_end = True if (latest_play.home_score > latest_play.away_score) and latest_play.inning_num >= 9:
elif abs(latest_play.home_score - latest_play.away_score) >= 10 and latest_play.inning_half == 'bot': logging.debug(f'bottom half and home team winning')
valid_end = True
if abs(latest_play.home_score - latest_play.away_score) >= 10:
logging.debug(f'bottom half and mercy')
valid_end = True
elif abs(latest_play.home_score - latest_play.away_score) >= 10 and latest_play.inning_half.lower() == 'bot':
logging.info(f'bottom half and it is a mercy')
valid_end = True valid_end = True
# valid_end = True # TODO: REMOVE THIS BEFORE GO-LIVE # valid_end = True # TODO: REMOVE THIS BEFORE GO-LIVE
@ -1817,10 +1859,11 @@ class Gameplay(commands.Cog):
logging.debug(f'setting location') logging.debug(f'setting location')
embed.add_field( embed.add_field(
name='Location', name='Location',
value=f'{interaction.guild.get_channel(this_game.channel_id).mention}', value=f'{interaction.guild.get_channel(this_game.channel_id).mention}'
inline=False
) )
embed.add_field(name='Game ID', value=f'{final_game["id"]}')
logging.debug(f'getting league name') logging.debug(f'getting league name')
if this_game.game_type == 'major-league': if this_game.game_type == 'major-league':
game_des = 'Major League' game_des = 'Major League'
@ -1845,7 +1888,8 @@ class Gameplay(commands.Cog):
f'{gs["hits"]["away"]: >2} | {gs["errors"]["away"]: >2} |\n' f'{gs["hits"]["away"]: >2} | {gs["errors"]["away"]: >2} |\n'
f'{home_team["abbrev"].replace("Gauntlet-", ""): <4} | {gs["runs"]["home"]: >2} | ' f'{home_team["abbrev"].replace("Gauntlet-", ""): <4} | {gs["runs"]["home"]: >2} | '
f'{gs["hits"]["home"]: >2} | {gs["errors"]["home"]: >2} |\n' f'{gs["hits"]["home"]: >2} | {gs["errors"]["home"]: >2} |\n'
f'\n```' f'\n```',
inline=False
) )
logging.debug(f'getting potg string') logging.debug(f'getting potg string')
@ -2722,7 +2766,7 @@ class Gameplay(commands.Cog):
away_team = await get_game_team(this_game, team_id=this_game.away_team_id) away_team = await get_game_team(this_game, team_id=this_game.away_team_id)
home_team = await get_game_team(this_game, team_id=this_game.home_team_id) home_team = await get_game_team(this_game, team_id=this_game.home_team_id)
ai_team = away_team if owner_team == home_team else home_team ai_team = away_team if owner_team['id'] == home_team['id'] else home_team
if this_play.batter.team_id == ai_team['id']: if this_play.batter.team_id == ai_team['id']:
await interaction.edit_original_response( await interaction.edit_original_response(

View File

@ -2136,9 +2136,9 @@ def get_pitching_decisions(game: StratGame, db_game_id: int):
if x.inning_half == 'Top' and home_pitcher != x.pitcher: if x.inning_half == 'Top' and home_pitcher != x.pitcher:
if save == home_pitcher: if save == home_pitcher:
if x.home_score > x.away_score: if x.home_score > x.away_score:
holds.append(save.card_id) holds.append(save)
else: else:
b_save.append(save.card_id) b_save.append(save)
save = None save = None
home_pitcher = x.pitcher home_pitcher = x.pitcher
@ -2149,9 +2149,9 @@ def get_pitching_decisions(game: StratGame, db_game_id: int):
elif x.inning_half == 'Bot' and away_pitcher != x.pitcher: elif x.inning_half == 'Bot' and away_pitcher != x.pitcher:
if save == away_pitcher: if save == away_pitcher:
if x.away_score > x.home_score: if x.away_score > x.home_score:
holds.append(save.card_id) holds.append(save)
else: else:
b_save.append(save.card_id) b_save.append(save)
save = None save = None
away_pitcher = x.pitcher away_pitcher = x.pitcher
@ -2171,7 +2171,7 @@ def get_pitching_decisions(game: StratGame, db_game_id: int):
# loser = Lineup.get_by_id(last_pa[0].pitcher_id) # pitcher from winning_run's last PA # loser = Lineup.get_by_id(last_pa[0].pitcher_id) # pitcher from winning_run's last PA
loser = x.pitcher loser = x.pitcher
if save == loser: if save == loser:
b_save.append(save.card_id) b_save.append(save)
save = None save = None
winner = home_pitcher if x.inning_half == 'Bot' else away_pitcher winner = home_pitcher if x.inning_half == 'Bot' else away_pitcher
@ -2185,7 +2185,7 @@ def get_pitching_decisions(game: StratGame, db_game_id: int):
# loser = Lineup.get_by_id(last_pa[0].pitcher_id) # pitcher from winning_run's last PA # loser = Lineup.get_by_id(last_pa[0].pitcher_id) # pitcher from winning_run's last PA
loser = x.pitcher loser = x.pitcher
if save == loser: if save == loser:
b_save.append(save.card_id) b_save.append(save)
save = None save = None
winner = home_pitcher if x.inning_half == 'Bot' else away_pitcher winner = home_pitcher if x.inning_half == 'Bot' else away_pitcher
@ -2199,7 +2199,7 @@ def get_pitching_decisions(game: StratGame, db_game_id: int):
# loser = Lineup.get_by_id(last_pa[0].pitcher_id) # pitcher from winning_run's last PA # loser = Lineup.get_by_id(last_pa[0].pitcher_id) # pitcher from winning_run's last PA
loser = x.pitcher loser = x.pitcher
if save == loser: if save == loser:
b_save.append(save.card_id) b_save.append(save)
save = None save = None
winner = home_pitcher if x.inning_half == 'Bot' else away_pitcher winner = home_pitcher if x.inning_half == 'Bot' else away_pitcher
@ -2213,7 +2213,7 @@ def get_pitching_decisions(game: StratGame, db_game_id: int):
# loser = Lineup.get_by_id(last_pa[0].pitcher_id) # pitcher from winning_run's last PA # loser = Lineup.get_by_id(last_pa[0].pitcher_id) # pitcher from winning_run's last PA
loser = x.pitcher loser = x.pitcher
if save == loser: if save == loser:
b_save.append(save.card_id) b_save.append(save)
save = None save = None
winner = home_pitcher if x.inning_half == 'Bot' else away_pitcher winner = home_pitcher if x.inning_half == 'Bot' else away_pitcher
@ -2221,7 +2221,7 @@ def get_pitching_decisions(game: StratGame, db_game_id: int):
logging.debug(f'is tied: {x}') logging.debug(f'is tied: {x}')
winner, loser = None, None winner, loser = None, None
if save: if save:
b_save.append(save.card_id) b_save.append(save)
save = None save = None
if home_pitcher.player_id not in decisions: if home_pitcher.player_id not in decisions:

View File

@ -151,7 +151,7 @@ async def get_starting_pitcher(this_team, this_game, this_event, this_run):
card_id = await ai_manager.get_or_create_card(starter, this_team) card_id = await ai_manager.get_or_create_card(starter, this_team)
return { return {
'game_id': this_game['id'], 'game_id': this_game.id,
'team_id': this_team['id'], 'team_id': this_team['id'],
'player_id': starter['player_id'], 'player_id': starter['player_id'],
'card_id': card_id, 'card_id': card_id,

View File

@ -18,7 +18,7 @@ from typing import Optional, Literal
SBA_SEASON = 7 SBA_SEASON = 7
PD_SEASON = 5 PD_SEASON = 6
SBA_COLOR = 'a6ce39' SBA_COLOR = 'a6ce39'
PD_PLAYERS = 'Paper Dynasty Players' PD_PLAYERS = 'Paper Dynasty Players'
SBA_PLAYERS_ROLE_NAME = f'Season {SBA_SEASON} Players' SBA_PLAYERS_ROLE_NAME = f'Season {SBA_SEASON} Players'