diff --git a/command_logic/logic_gameplay.py b/command_logic/logic_gameplay.py index db1b42f..b29256b 100644 --- a/command_logic/logic_gameplay.py +++ b/command_logic/logic_gameplay.py @@ -164,7 +164,7 @@ async def get_scorebug_embed(session: Session, this_game: Game, full_length: boo if curr_play.on_third is not None: runcard = curr_play.on_third.card.batterscouting.battingcard baserunner_string += f'On Third: {curr_play.on_third.player.name_card_link('batting')}\nSteal: {steal_string(runcard)}, Run: {runcard.running}\n' - logger.info(f'gameplay_models - Game.get_scorebug_embed - baserunner_string: {baserunner_string}') + logger.info(f'gameplay_models - get_scorebug_embed - baserunner_string: {baserunner_string}') pitchingcard = curr_play.pitcher.card.pitcherscouting.pitchingcard battingcard = curr_play.batter.card.batterscouting.battingcard @@ -172,6 +172,7 @@ async def get_scorebug_embed(session: Session, this_game: Game, full_length: boo pit_string = f'{pitchingcard.hand.upper()}HP | {curr_play.pitcher.player.name_card_link('pitching')}' bat_string = f'{curr_play.batter.batting_order}. {battingcard.hand.upper()} | {curr_play.batter.player.name_card_link('batting')}' if len(baserunner_string) > 0: + logger.info(f'Adding pitcher hold to scorebug') pitchingcard = curr_play.pitcher.card.pitcherscouting.pitchingcard pit_string += f'\nHold: {"+" if pitchingcard.hold > 0 else ""}{pitchingcard.hold}, WP: {pitchingcard.wild_pitch}, Bk: {pitchingcard.balk}' @@ -186,9 +187,11 @@ async def get_scorebug_embed(session: Session, this_game: Game, full_length: boo name='Batter', value=bat_string ) + logger.info(f'Setting embed image to batter card') embed.set_image(url=curr_play.batter.player.batter_card_url) if len(baserunner_string) > 0: + logger.info(f'Adding baserunner info to embed') embed.add_field(name=' ', value=' ', inline=False) embed.add_field(name='Baserunners', value=baserunner_string) @@ -202,6 +205,7 @@ async def get_scorebug_embed(session: Session, this_game: Game, full_length: boo embed.add_field(name='Catcher', value=cat_string) if curr_play.ai_is_batting and curr_play.on_base_code > 0: + logger.info(f'Checking on baserunners for jump') if curr_play.on_base_code in [2, 4]: to_base = 3 elif curr_play.on_base_code in [1, 5]: @@ -212,7 +216,9 @@ async def get_scorebug_embed(session: Session, this_game: Game, full_length: boo jump_resp = curr_play.managerai.check_jump(session, this_game, to_base=to_base) ai_note = jump_resp.ai_note else: + logger.info(f'Checking defensive alignment') def_align = curr_play.managerai.defense_alignment(session, this_game) + logger.info(f'def_align: {def_align}') ai_note = def_align.ai_note logger.info(f'gameplay_models - get_scorebug_embed - ai_note: {ai_note}') @@ -381,7 +387,8 @@ def get_wpa(this_play: Play, next_play: Play): new_win_ex = WPA_DF.loc[f'{next_play.inning_half}_{inning_num}_{next_play.starting_outs}_out_{next_play.on_base_code}_obc_{new_rd}_home_run_diff'].home_win_ex # print(f'new_win_ex = {new_win_ex}') - old_win_ex = WPA_DF.loc[f'{this_play.inning_half}_{this_play.inning_num}_{this_play.starting_outs}_out_{this_play.on_base_code}_obc_{old_rd}_home_run_diff'].home_win_ex + inning_num = 9 if this_play.inning_num > 9 else this_play.inning_num + old_win_ex = WPA_DF.loc[f'{this_play.inning_half}_{inning_num}_{this_play.starting_outs}_out_{this_play.on_base_code}_obc_{old_rd}_home_run_diff'].home_win_ex # print(f'old_win_ex = {old_win_ex}') wpa = float(round(new_win_ex - old_win_ex, 3)) @@ -684,17 +691,21 @@ def log_run_scored(session: Session, runner: Lineup, this_play: Play, is_earned: """ Commits last_ab """ + logger.info(f'Logging a run for runner ID {runner.id} in Game {this_play.game.id}') last_ab = get_players_last_pa(session, lineup_member=runner) last_ab.run = 1 + logger.info(f'last_ab: {last_ab}') errors = session.exec(select(func.count(Play.id)).where( - Play.inning_num == last_ab.inning_num, Play.inning_half == last_ab.inning_half, Play.error == 1 + Play.game == this_play.game, Play.inning_num == last_ab.inning_num, Play.inning_half == last_ab.inning_half, Play.error == 1 )).one() outs = session.exec(select(func.sum(Play.outs)).where( - Play.inning_num == last_ab.inning_num, Play.inning_half == last_ab.inning_half + Play.game == this_play.game, Play.inning_num == last_ab.inning_num, Play.inning_half == last_ab.inning_half )).one() + logger.info(f'errors: {errors} / outs: {outs}') if errors + outs + this_play.error >= 3: + logger.info(f'unearned run') is_earned = False last_ab.e_run = 1 if is_earned else 0 @@ -1728,6 +1739,7 @@ async def popouts(session: Session, interaction: discord.Interaction, this_play: async def hit_by_pitch(session: Session, interaction: discord.Interaction, this_play: Play): this_play.ab, this_play.hbp = 0, 1 + this_play.batter_final = 1 this_play = advance_runners(session, this_play, num_bases=1, only_forced=True) session.add(this_play) @@ -2379,6 +2391,8 @@ def undo_play(session: Session, this_play: Play): logger.warning(f'Deleting lineup IDs: {new_player_ids}') session.exec(delete(Lineup).where(Lineup.id.in_(new_player_ids))) + # TODO: check for runners that scored in previous play, find their last AB, and set run and e_run to 0 + session.commit() try: @@ -2535,8 +2549,8 @@ async def get_game_summary_embed(session: Session, interaction: discord.Interact all_poop = game_summary['pooper'] for line in all_poop: - poop_line = f'{player_name} - ' player_name = f'{get_player_name_from_dict(line['player'])}' + poop_line = f'{player_name} - ' if 'hr' in line: poop_line += f'{line["hit"]}-{line["ab"]}' @@ -2752,7 +2766,7 @@ async def complete_game(session: Session, interaction: discord.Interaction, this if news_ticker is not None: await news_ticker.send(content=None, embed=summary_embed) - await interaction.channel.send(content=None, embed=summary_embed) + # await interaction.channel.send(content=None, embed=summary_embed) await interaction.edit_original_response(content=None, embed=summary_embed) game_id = this_game.id diff --git a/in_game/gameplay_models.py b/in_game/gameplay_models.py index c7cdbba..e26885c 100644 --- a/in_game/gameplay_models.py +++ b/in_game/gameplay_models.py @@ -319,6 +319,7 @@ class ManagerAi(ManagerAiBase, table=True): runner = this_play.on_first if runner is None: log_exception(CardNotFoundException, f'Attempted to check a jump to 2nd base, but no runner found on first.') + logger.info(f'Checking steal numbers for {runner.player.name} in Game {this_game.id}') match self.steal: case 10: @@ -344,12 +345,12 @@ class ManagerAi(ManagerAiBase, table=True): this_resp.ai_note = f'- WILL SEND **{runner.player.name}** to second!' elif this_resp.must_auto_jump and not runner_card.steal_auto: - this_resp.ai_note = f'' + logger.info(f'No jump ai note') else: jump_safe_range = runner_card.steal_high + battery_hold nojump_safe_range = runner_card.steal_low + battery_hold - logger.info(f'jump_safe_range: {jump_safe_range} / nojump_safe_range: {nojump_safe_range}') + logger.info(f'jump_safe_range: {jump_safe_range} / nojump_safe_range: {nojump_safe_range} / min_safe: {this_resp.min_safe}') if this_resp.min_safe <= nojump_safe_range: this_resp.ai_note = f'- SEND **{runner.player.name}** to second!' @@ -373,18 +374,18 @@ class ManagerAi(ManagerAiBase, table=True): if self.steal == 10 and num_outs < 2 and run_diff <= 5: this_resp.run_if_auto_jump = True elif self.steal <= 5: - this_resp.must_auto_jump = True + this_resp.must_auto_jump = True runner_card = runner.card.batterscouting.battingcard if this_resp.run_if_auto_jump and runner_card.steal_auto: this_resp.ai_note = f'- SEND **{runner.player.name}** to third!' - elif this_resp.must_auto_jump and not runner_card.steal_auto: - pass + elif this_resp.must_auto_jump and not runner_card.steal_auto or this_resp.min_safe is None: + logger.info(f'No jump ai note') else: jump_safe_range = runner_card.steal_low + battery_hold - logger.info(f'jump_safe_range: {jump_safe_range}') + logger.info(f'jump_safe_range: {jump_safe_range} / min_safe: {this_resp.min_safe}') if this_resp.min_safe <= jump_safe_range: this_resp.ai_note = f'- SEND **{runner.player.name}** to third!' @@ -561,27 +562,31 @@ class ManagerAi(ManagerAiBase, table=True): battery_hold = pitcher_hold + catcher_hold if this_play.starting_outs == 2 and this_play.on_base_code > 0: + logger.info(f'Checking for holds with 2 outs') if this_play.on_base_code == 1: this_resp.hold_first = True this_resp.ai_note += f'- hold {this_play.on_first.player.name} on 1st\n' elif this_play.on_base_code == 2: this_resp.hold_second = True this_resp.ai_note += f'- hold {this_play.on_second.player.name} on 2nd\n' - elif this_play.on_base_code in [4, 5, 7]: + elif this_play.on_base_code in [4, 7]: this_resp.hold_first = True this_resp.hold_second = True this_resp.ai_note += f'- hold {this_play.on_first.player.name} on 1st\n- hold {this_play.on_second.player.name} on 2nd\n' - # elif self.on_base_code == 5: - # this_resp.ai_note += f'- hold the runner on first\n' + elif this_play.on_base_code == 5: + this_resp.hold_first = True + this_resp.ai_note += f'- hold {this_play.on_first.player.name} on first\n' elif this_play.on_base_code == 6: this_resp.hold_second = True this_resp.ai_note += f'- hold {this_play.on_second.player.name} on 2nd\n' elif this_play.on_base_code in [1, 5]: + logger.info(f'Checking for hold with runner on first') runner = this_play.on_first.player if this_play.on_first.card.batterscouting.battingcard.steal_auto and ((this_play.on_first.card.batterscouting.battingcard.steal_high + battery_hold) >= (12 - aggression)): this_resp.hold_first = True this_resp.ai_note += f'- hold {runner.name} on 1st\n' elif this_play.on_base_code in [2, 4]: + logger.info(f'Checking for hold with runner on second') if (this_play.on_second.card.batterscouting.battingcard.steal_low + max(battery_hold, 5)) >= (14 - aggression): this_resp.hold_second = True this_resp.ai_note += f'- hold {this_play.on_second.player.name} on 2nd\n'