From 0c814ceb2da9d1e8ffe49b902c4fbed377038a39 Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 11 Oct 2021 13:53:29 +0100 Subject: Set `AI.user` to @Sir Lancebot --- bot/exts/fun/tic_tac_toe.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/exts/fun/tic_tac_toe.py b/bot/exts/fun/tic_tac_toe.py index 5c4f8051..49620d02 100644 --- a/bot/exts/fun/tic_tac_toe.py +++ b/bot/exts/fun/tic_tac_toe.py @@ -72,7 +72,8 @@ class Player: class AI: """Tic Tac Toe AI class for against computer gaming.""" - def __init__(self, symbol: str): + def __init__(self, ctx: Context, symbol: str): + self.user = ctx.me self.symbol = symbol async def get_move(self, board: dict[int, str], _: discord.Message) -> tuple[bool, int]: @@ -97,8 +98,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: @@ -265,7 +266,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, Emojis.o_square)], ctx ) else: -- cgit v1.2.3 From 462b83c8150bbc9121d87cf8ee0e61d850776fc6 Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 11 Oct 2021 14:17:38 +0100 Subject: Add missing `Game.channel` attribute --- bot/exts/fun/tic_tac_toe.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot') diff --git a/bot/exts/fun/tic_tac_toe.py b/bot/exts/fun/tic_tac_toe.py index 49620d02..1ebf8d11 100644 --- a/bot/exts/fun/tic_tac_toe.py +++ b/bot/exts/fun/tic_tac_toe.py @@ -108,6 +108,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], -- cgit v1.2.3 From 860c137f868ff9c91df0669a33dd9d551cbcc4a5 Mon Sep 17 00:00:00 2001 From: Izan Date: Sun, 17 Oct 2021 13:09:54 +0100 Subject: Address review & make `AI.get_move` a staticmethod --- bot/exts/fun/tic_tac_toe.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'bot') diff --git a/bot/exts/fun/tic_tac_toe.py b/bot/exts/fun/tic_tac_toe.py index 1ebf8d11..946b6f7b 100644 --- a/bot/exts/fun/tic_tac_toe.py +++ b/bot/exts/fun/tic_tac_toe.py @@ -72,11 +72,12 @@ class Player: class AI: """Tic Tac Toe AI class for against computer gaming.""" - def __init__(self, ctx: Context, symbol: str): - self.user = ctx.me + 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())] @@ -175,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) @@ -267,7 +269,7 @@ class TicTacToe(Cog): return if opponent is None: game = Game( - [Player(ctx.author, ctx, Emojis.x_square), AI(ctx, Emojis.o_square)], + [Player(ctx.author, ctx, Emojis.x_square), AI(ctx.me, Emojis.o_square)], ctx ) else: -- cgit v1.2.3