diff --git a/Dockerfile b/Dockerfile index d946150..29bb9d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,6 @@ FROM python:3.8-slim WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y git COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt diff --git a/ai_manager.py b/ai_manager.py index 947050b..de53a28 100644 --- a/ai_manager.py +++ b/ai_manager.py @@ -3,7 +3,7 @@ import logging import random import pydantic -from db_calls_gameplay import StratPlay, get_team_lineups +from db_calls_gameplay import StratPlay, StratGame, get_one_lineup from db_calls import db_get, db_post from peewee import * from typing import Optional, Literal @@ -489,3 +489,10 @@ def get_relief_pitcher(this_play: StratPlay, ai_team: dict, used_pitchers: list, 'batting_order': 10, 'after_play': this_play.play_num - 1 } + + +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 + return get_one_lineup(this_game.id, team_id=p_team_id, position='P', active=True) diff --git a/cogs/gameplay.py b/cogs/gameplay.py index f4b3fba..4d6a504 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -358,8 +358,15 @@ class Gameplay(commands.Cog): this_ai = get_manager(game) logging.debug(f'Pitching team is an AI') gm_name = f'{game_state["pitcher"]["team"]["gmname"]}' - n_pitcher = await next_pitcher(game_state['curr_play'], game_state["pitcher"]["team"], self.bot) - logging.debug(f'n_pitcher: {n_pitcher}') + # n_pitcher = await next_pitcher(game_state['curr_play'], game_state["pitcher"]["team"], self.bot) + # logging.debug(f'n_pitcher: {n_pitcher}') + used_pitchers = await get_team_lineups( + game_id=game_state['curr_play'].game.id, + team_id=game_state["pitcher"]["team"]['id'], + inc_inactive=True, + pitchers_only=True, + as_string=False + ) last_inning_ender = get_last_inning_end_play( game.id, @@ -376,23 +383,24 @@ class Gameplay(commands.Cog): elif game_state['curr_play'].is_new_inning and game.short_game and game_state['curr_play'].inning_num != 1: logging.debug(f'{game_state["pitcher"]["team"]["sname"]} going the to pen.') - if 'card_id' in n_pitcher: - replace_pitcher(game_state['pitcher']['team'], game_state['curr_play'], n_pitcher['card_id']) - embed.set_thumbnail(url=n_pitcher['player']['image']) + if len(used_pitchers) < 8: + make_sub(ai_manager.get_relief_pitcher( + game_state['curr_play'], game_state['pitcher']['team'], used_pitchers, game.game_type + )) + new_pitcher = await get_player(game, ai_manager.get_pitcher(game, game_state['curr_play'])) + embed.set_thumbnail(url=new_pitcher['image']) embed.add_field( name=f'SUBSTITUTION', value=f'The {game_state["pitcher"]["team"]["sname"]} have brought in ' - f'{n_pitcher["player"]["p_name"]} to pitch.' + f'[{new_pitcher["p_name"]}]({new_pitcher["image"]}) to pitch.' ) else: ai_note += f'- continue with auto-fatigued {game_state["pitcher"]["p_name"]}\n' else: - if 'card_id' in n_pitcher: - logging.debug(f'{game_state["pitcher"]["team"]["sname"]} are warming up {n_pitcher}.') + if len(used_pitchers) < 8: ai_note += f'- go to the pen if the pitcher fatigues (`/log ai-pitcher-sub`)\n' else: - logging.warning(f'{game_state["pitcher"]["team"]["sname"]} are out of pitchers.') ai_note += f' - continue with {game_state["pitcher"]["p_name"]}\n' logging.debug(f'past the first conditional in AI stuff')