From 994c920dd1cbac699774298bee6ad38edd95bfe9 Mon Sep 17 00:00:00 2001 From: LeraBulanova Date: Thu, 22 Sep 2022 19:03:18 +0300 Subject: [PATCH] Low cyclomatic complexity of win_check function from D to A --- tictactoe/ticTacToe.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tictactoe/ticTacToe.py b/tictactoe/ticTacToe.py index e4182ee..82c4662 100644 --- a/tictactoe/ticTacToe.py +++ b/tictactoe/ticTacToe.py @@ -69,15 +69,16 @@ def place_marker(board, marker, position): board[position] = marker # Function to check if player has won -def win_check(board, mark): - return ((board[1] == mark and board[2] == mark and board[3] == mark) or # Horizontal Bottom - (board[4] == mark and board[5] == mark and board[6] == mark) or # Horizontal Middle - (board[7] == mark and board[8] == mark and board[9] == mark) or # Horizontal Top - (board[7] == mark and board[4] == mark and board[1] == mark) or # Vertical Left - (board[8] == mark and board[5] == mark and board[2] == mark) or # Vertical Middle - (board[9] == mark and board[6] == mark and board[3] == mark) or # Vertical Right - (board[7] == mark and board[5] == mark and board[3] == mark) or # Diagonal Left to Right Bottom - (board[9] == mark and board[5] == mark and board[1] == mark)) # Diagonal Right to Left Bottom +def win_check(board, mark): + solution = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8], [3, 6, 9], [1, 5, 9], [3, 5, 7]] + for combinations in solution: + check_combination = True + for i in combinations: + if board[i] != mark: + check_combination = False + if check_combination: + return True + return False # Function to decide which player goes first import random