Skip to content

Low cyclomatic complexity of win_check() function from D to A #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions tictactoe/ticTacToe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down