diff options
Diffstat (limited to 'bot/exts/evergreen/tic_tac_toe.py')
| -rw-r--r-- | bot/exts/evergreen/tic_tac_toe.py | 24 | 
1 files changed, 12 insertions, 12 deletions
diff --git a/bot/exts/evergreen/tic_tac_toe.py b/bot/exts/evergreen/tic_tac_toe.py index 164e056d..5c4f8051 100644 --- a/bot/exts/evergreen/tic_tac_toe.py +++ b/bot/exts/evergreen/tic_tac_toe.py @@ -1,6 +1,6 @@  import asyncio  import random -import typing as t +from typing import Callable, Optional, Union  import discord  from discord.ext.commands import Cog, Context, check, group, guild_only @@ -15,7 +15,7 @@ CONFIRMATION_MESSAGE = (  ) -def check_win(board: t.Dict[int, str]) -> bool: +def check_win(board: dict[int, str]) -> bool:      """Check from board, is any player won game."""      return any(          ( @@ -42,7 +42,7 @@ class Player:          self.ctx = ctx          self.symbol = symbol -    async def get_move(self, board: t.Dict[int, str], msg: discord.Message) -> t.Tuple[bool, t.Optional[int]]: +    async def get_move(self, board: dict[int, str], msg: discord.Message) -> tuple[bool, Optional[int]]:          """          Get move from user. @@ -75,7 +75,7 @@ class AI:      def __init__(self, symbol: str):          self.symbol = symbol -    async def get_move(self, board: t.Dict[int, str], _: discord.Message) -> t.Tuple[bool, int]: +    async def get_move(self, 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())] @@ -104,7 +104,7 @@ class AI:  class Game:      """Class that contains information and functions about Tic Tac Toe game.""" -    def __init__(self, players: t.List[t.Union[Player, AI]], ctx: Context): +    def __init__(self, players: list[Union[Player, AI]], ctx: Context):          self.players = players          self.ctx = ctx          self.board = { @@ -122,13 +122,13 @@ class Game:          self.current = self.players[0]          self.next = self.players[1] -        self.winner: t.Optional[t.Union[Player, AI]] = None -        self.loser: t.Optional[t.Union[Player, AI]] = None +        self.winner: Optional[Union[Player, AI]] = None +        self.loser: Optional[Union[Player, AI]] = None          self.over = False          self.canceled = False          self.draw = False -    async def get_confirmation(self) -> t.Tuple[bool, t.Optional[str]]: +    async def get_confirmation(self) -> tuple[bool, Optional[str]]:          """          Ask does user want to play TicTacToe against requester. First player is always requester. @@ -227,14 +227,14 @@ class Game:          self.over = True -def is_channel_free() -> t.Callable: +def is_channel_free() -> Callable:      """Check is channel where command will be invoked free."""      async def predicate(ctx: Context) -> bool:          return all(game.channel != ctx.channel for game in ctx.cog.games if not game.over)      return check(predicate) -def is_requester_free() -> t.Callable: +def is_requester_free() -> Callable:      """Check is requester not already in any game."""      async def predicate(ctx: Context) -> bool:          return all( @@ -247,13 +247,13 @@ class TicTacToe(Cog):      """TicTacToe cog contains tic-tac-toe game commands."""      def __init__(self): -        self.games: t.List[Game] = [] +        self.games: list[Game] = []      @guild_only()      @is_channel_free()      @is_requester_free()      @group(name="tictactoe", aliases=("ttt", "tic"), invoke_without_command=True) -    async def tic_tac_toe(self, ctx: Context, opponent: t.Optional[discord.User]) -> None: +    async def tic_tac_toe(self, ctx: Context, opponent: Optional[discord.User]) -> None:          """Tic Tac Toe game. Play against friends or AI. Use reactions to add your mark to field."""          if opponent == ctx.author:              await ctx.send("You can't play against yourself.")  |