diff options
Diffstat (limited to 'bot/exts/evergreen')
| -rw-r--r-- | bot/exts/evergreen/rps.py | 57 | ||||
| -rw-r--r-- | bot/exts/evergreen/tic_tac_toe.py | 14 |
2 files changed, 66 insertions, 5 deletions
diff --git a/bot/exts/evergreen/rps.py b/bot/exts/evergreen/rps.py new file mode 100644 index 00000000..c6bbff46 --- /dev/null +++ b/bot/exts/evergreen/rps.py @@ -0,0 +1,57 @@ +from random import choice + +from discord.ext import commands + +from bot.bot import Bot + +CHOICES = ["rock", "paper", "scissors"] +SHORT_CHOICES = ["r", "p", "s"] + +# Using a dictionary instead of conditions to check for the winner. +WINNER_DICT = { + "r": { + "r": 0, + "p": -1, + "s": 1, + }, + "p": { + "r": 1, + "p": 0, + "s": -1, + }, + "s": { + "r": -1, + "p": 1, + "s": 0, + } +} + + +class RPS(commands.Cog): + """Rock Paper Scissors. The Classic Game!""" + + @commands.command(case_insensitive=True) + async def rps(self, ctx: commands.Context, move: str) -> None: + """Play the classic game of Rock Paper Scissors with your own sir-lancebot!""" + move = move.lower() + player_mention = ctx.author.mention + + if move not in CHOICES and move not in SHORT_CHOICES: + raise commands.BadArgument(f"Invalid move. Please make move from options: {', '.join(CHOICES).upper()}.") + + bot_move = choice(CHOICES) + # value of player_result will be from (-1, 0, 1) as (lost, tied, won). + player_result = WINNER_DICT[move[0]][bot_move[0]] + + if player_result == 0: + message_string = f"{player_mention} You and Sir Lancebot played {bot_move}, it's a tie." + await ctx.send(message_string) + elif player_result == 1: + await ctx.send(f"Sir Lancebot played {bot_move}! {player_mention} won!") + else: + await ctx.send(f"Sir Lancebot played {bot_move}! {player_mention} lost!") + + +def setup(bot: Bot) -> None: + """Load the RPS Cog.""" + bot.add_cog(RPS(bot)) diff --git a/bot/exts/evergreen/tic_tac_toe.py b/bot/exts/evergreen/tic_tac_toe.py index bd5e0102..48e8e142 100644 --- a/bot/exts/evergreen/tic_tac_toe.py +++ b/bot/exts/evergreen/tic_tac_toe.py @@ -79,7 +79,7 @@ class AI: """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())] - for symbol in (Emojis.o, Emojis.x): + for symbol in (Emojis.o_square, Emojis.x_square): for move in possible_moves: board_copy = board.copy() board_copy[move] = symbol @@ -265,12 +265,12 @@ class TicTacToe(Cog): return if opponent is None: game = Game( - [Player(ctx.author, ctx, Emojis.x), AI(Emojis.o)], + [Player(ctx.author, ctx, Emojis.x_square), AI(Emojis.o_square)], ctx ) else: game = Game( - [Player(ctx.author, ctx, Emojis.x), Player(opponent, ctx, Emojis.o)], + [Player(ctx.author, ctx, Emojis.x_square), Player(opponent, ctx, Emojis.o_square)], ctx ) self.games.append(game) @@ -317,8 +317,12 @@ class TicTacToe(Cog): await ctx.send("Game don't exist.") return game = self.games[game_id - 1] - await ctx.send(f"{game.winner} :trophy: vs {game.loser}") - await ctx.send(game.format_board()) + + embed = discord.Embed( + title=f"Match #{game_id} Game Board", + description=f"{game.winner} :trophy: vs {game.loser}\n\n{game.format_board()}" + ) + await ctx.send(embed=embed) def setup(bot: Bot) -> None: |