From 94a39f3f7f1b19b678572d2d494f07535e52a32f Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Thu, 9 Apr 2020 19:05:33 +0300 Subject: (TicTacToe): Created helper function `Game.check_for_win`. --- bot/exts/evergreen/tic_tac_toe.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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.") -- cgit v1.2.3