Get RP Fixes

This commit is contained in:
Cal Corum 2023-05-04 10:51:31 -05:00
parent d3ba2f0e96
commit 33e5e97726
2 changed files with 30 additions and 15 deletions

View File

@ -416,12 +416,15 @@ async def get_starting_pitcher(team_object: dict, game_id: int, is_home: bool, l
}
async def get_relief_pitcher(this_play: StratPlay, ai_team: dict, used_pitchers: list, league_name: str = None) -> dict:
async def get_relief_pitcher(this_play: StratPlay, ai_team: dict, league_name: str = None) -> dict:
used_codes = []
for x in used_pitchers:
used_players = await get_team_lineups(
game_id=this_play.game.id, team_id=ai_team['id'], inc_inactive=True, as_string=False
)
for x in used_players:
c_query = await db_get('cards', object_id=x.card_id)
used_codes.append(c_query["player"]["strat_code"])
logging.info(f'get_rp - used_pitchers: {used_codes}')
logging.info(f'get_rp - used_players: {used_codes}')
reliever = None
attempts = 0
@ -441,17 +444,18 @@ async def get_relief_pitcher(this_play: StratPlay, ai_team: dict, used_pitchers:
# Pull relievers sorted by current cost
params = [
('mlbclub', ai_team['lname']), ('pos_include', 'RP'), ('inc_dex', False), ('sort_by', 'cost-desc')
('mlbclub', ai_team['lname']), ('pos_include', 'RP'), ('inc_dex', False), ('sort_by', 'cost-desc'),
('limit', 15)
]
params.extend(set_params)
alt_flag = False
use_best = False
if attempts == 1:
# Try to get long man
if this_play.inning_num < 6:
logging.info(f'get_rp - game {this_play.game.id} try for long man')
params.append(('pos_include', 'SP'))
alt_flag = True
# use_best = True
# Try to get closer
elif this_play.inning_num > 8:
@ -459,7 +463,7 @@ async def get_relief_pitcher(this_play: StratPlay, ai_team: dict, used_pitchers:
(this_play.inning_half == 'bot' and this_play.away_score >= this_play.home_score):
logging.info(f'get_rp - game {this_play.game.id} try for closer')
params.append(('pos_include', 'CP'))
alt_flag = True
use_best = True
else:
params.append(('pos_exclude', 'CP'))
@ -479,7 +483,7 @@ async def get_relief_pitcher(this_play: StratPlay, ai_team: dict, used_pitchers:
raise ConnectionError(f'Error pulling starting pitchers for the {ai_team["lname"]}. Cal help plz.')
if pitchers['count'] > 0:
if alt_flag or this_play.inning_num > 9 or attempts > 2:
if use_best or this_play.inning_num > 9 or attempts > 2:
start = 0
else:
start = 9 - this_play.inning_num
@ -500,9 +504,9 @@ async def get_relief_pitcher(this_play: StratPlay, ai_team: dict, used_pitchers:
def get_pitcher(this_game: StratGame, this_play: StratPlay):
p_team_id = this_game.away_team_id
if this_play.inning_half == 'top':
p_team_id = this_game.home_team_id
if this_play.inning_half == 'top':
p_team_id = this_game.away_team_id
return get_one_lineup(this_game.id, team_id=p_team_id, position='P', active=True)
@ -526,6 +530,7 @@ async def pitching_ai_note(this_play: StratPlay, this_pitcher: dict):
pitcher = this_pitcher
# Pitcher Substitutions
new_pitcher = None
if last_inning_ender and last_inning_ender.pitcher != this_play.pitcher:
logging.debug(f'{this_pitcher["team"]["sname"]} not making a change.')
@ -536,15 +541,16 @@ async def pitching_ai_note(this_play: StratPlay, this_pitcher: dict):
if len(used_pitchers) < 8:
make_sub(await get_relief_pitcher(
this_play, this_pitcher['team'], used_pitchers, this_play.game.game_type
this_play, this_pitcher['team'], this_play.game.game_type
))
pitcher = await get_player(this_play.game, get_pitcher(this_play.game, this_play))
new_pitcher = pitcher
else:
ai_note += f'- continue with auto-fatigued {this_pitcher["p_name"]}\n'
else:
if len(used_pitchers) == 1:
ai_note += f'- go to the pen if the pitcher fatigues **and has allowed 5+ baserunners** ' \
ai_note += f'- go to the pen if the pitcher fatigues __and has allowed 5+ baserunners__ ' \
f'(`/log ai-pitcher-sub`)\n'
elif len(used_pitchers) < 8:
ai_note += f'- go to the pen if the pitcher fatigues (`/log ai-pitcher-sub`)\n'
@ -580,7 +586,8 @@ async def pitching_ai_note(this_play: StratPlay, this_pitcher: dict):
return {
'note': ai_note,
'pitcher': pitcher,
'gm_name': gm_name
'gm_name': gm_name,
'sub': new_pitcher
}

View File

@ -443,10 +443,18 @@ class Gameplay(commands.Cog):
# AI Team is pitching
if game_state['pitcher']['team']['is_ai']:
ai_data = await ai_manager.pitching_ai_note(game_state['curr_play'], game_state['pitcher'])
logging.info(f'ai_data: {ai_data}')
ai_note = ai_data['note']
gm_name = ai_data['gm_name']
embed.set_thumbnail(url=ai_data['pitcher']["image"])
if ai_data['sub'] is not None:
embed.add_field(
name='SUBSTITUTION',
value=f'The {game_state["pitcher"]["team"]["sname"]} have brought in '
f'{ai_data["sub"]["description"]} to pitch.'
)
# AI Team is batting
elif game_state['batter']['team']['is_ai']:
embed.set_thumbnail(url=game_state["pitcher"]["image"])
@ -2331,9 +2339,9 @@ class Gameplay(commands.Cog):
# make_sub(this_lineup)
used_pitchers = await get_team_lineups(
game_id=this_play.game.id, team_id=ai_team['id'], inc_inactive=True, pitchers_only=True, as_string=False
game_id=this_play.game.id, team_id=ai_team['id'], inc_inactive=True, as_string=False
)
make_sub(await ai_manager.get_relief_pitcher(this_play, ai_team, used_pitchers, this_game.game_type))
make_sub(await ai_manager.get_relief_pitcher(this_play, ai_team, this_game.game_type))
await interaction.edit_original_response(
content=None,
embed=await self.get_game_state_embed(this_game)