diff options
| author | 2021-10-17 16:17:02 +0400 | |
|---|---|---|
| committer | 2021-10-17 16:17:02 +0400 | |
| commit | 559e76ffbef7af85132d86f2e3ab8acf7e7f5eef (patch) | |
| tree | 5b470a59f56b9cdd121c329cc09f1d37dd598676 /bot/exts | |
| parent | Merge pull request #914 from python-discord/issue-command-fixes (diff) | |
| parent | Merge branch 'main' into fix-issue-898 (diff) | |
Merge pull request #899 from python-discord/fix-issue-898
Set `AI.user` to @Sir Lancebot
Diffstat (limited to 'bot/exts')
| -rw-r--r-- | bot/exts/fun/tic_tac_toe.py | 16 | 
1 files changed, 10 insertions, 6 deletions
| diff --git a/bot/exts/fun/tic_tac_toe.py b/bot/exts/fun/tic_tac_toe.py index 5c4f8051..946b6f7b 100644 --- a/bot/exts/fun/tic_tac_toe.py +++ b/bot/exts/fun/tic_tac_toe.py @@ -72,10 +72,12 @@ class Player:  class AI:      """Tic Tac Toe AI class for against computer gaming.""" -    def __init__(self, symbol: str): +    def __init__(self, bot_user: discord.Member, symbol: str): +        self.user = bot_user          self.symbol = symbol -    async def get_move(self, board: dict[int, str], _: discord.Message) -> tuple[bool, int]: +    @staticmethod +    async def get_move(board: dict[int, str], _: discord.Message) -> tuple[bool, int]:          """Get move from AI. AI use Minimax strategy."""          possible_moves = [i for i, emoji in board.items() if emoji in list(Emojis.number_emojis.values())] @@ -97,8 +99,8 @@ class AI:          return False, random.choice(open_edges)      def __str__(self) -> str: -        """Return `AI` as user name.""" -        return "AI" +        """Return mention of @Sir Lancebot.""" +        return self.user.mention  class Game: @@ -107,6 +109,7 @@ class Game:      def __init__(self, players: list[Union[Player, AI]], ctx: Context):          self.players = players          self.ctx = ctx +        self.channel = ctx.channel          self.board = {              1: Emojis.number_emojis[1],              2: Emojis.number_emojis[2], @@ -173,7 +176,8 @@ class Game:              self.canceled = True              return False, "User declined" -    async def add_reactions(self, msg: discord.Message) -> None: +    @staticmethod +    async def add_reactions(msg: discord.Message) -> None:          """Add number emojis to message."""          for nr in Emojis.number_emojis.values():              await msg.add_reaction(nr) @@ -265,7 +269,7 @@ class TicTacToe(Cog):              return          if opponent is None:              game = Game( -                [Player(ctx.author, ctx, Emojis.x_square), AI(Emojis.o_square)], +                [Player(ctx.author, ctx, Emojis.x_square), AI(ctx.me, Emojis.o_square)],                  ctx              )          else: | 
