diff options
| author | 2020-04-09 19:05:33 +0300 | |
|---|---|---|
| committer | 2020-04-09 19:05:33 +0300 | |
| commit | 94a39f3f7f1b19b678572d2d494f07535e52a32f (patch) | |
| tree | 255fedef3e8a7c3bf790ba9e1c188b9182c26f0a /bot/exts/evergreen | |
| parent | (TicTacToe): Created `edit_board` function to `Game`, made fixes to `Player.g... (diff) | |
(TicTacToe): Created helper function `Game.check_for_win`.
Diffstat (limited to 'bot/exts/evergreen')
| -rw-r--r-- | bot/exts/evergreen/tic_tac_toe.py | 18 | 
1 files changed, 18 insertions, 0 deletions
| diff --git a/bot/exts/evergreen/tic_tac_toe.py b/bot/exts/evergreen/tic_tac_toe.py index b9e44220..970f359d 100644 --- a/bot/exts/evergreen/tic_tac_toe.py +++ b/bot/exts/evergreen/tic_tac_toe.py @@ -134,6 +134,24 @@ class Game:                  c = 0          await message.edit(content=msg) +    async def check_for_win(self) -> bool: +        """Check from board, is any player won game.""" +        if ( +            # Horizontal +            self.board[1] == self.board[2] == self.board[3] +            or self.board[4] == self.board[5] == self.board[6] +            or self.board[7] == self.board[8] == self.board[9] +            # Vertical +            or self.board[1] == self.board[4] == self.board[7] +            or self.board[2] == self.board[5] == self.board[8] +            or self.board[3] == self.board[6] == self.board[9] +            # Diagonal +            or self.board[1] == self.board[5] == self.board[9] +            or self.board[3] == self.board[5] == self.board[7] +        ): +            return True +        return False +      async def play(self) -> None:          """Start and handle game."""          await self.ctx.send("It's time for game! Let's begin.") | 
