-
Notifications
You must be signed in to change notification settings - Fork 6
incorrect tie project - tic-tac-toe sample answer.py #1
Copy link
Copy link
Open
Description
I think there is a bug in the VictoryFor function which results in the moment when the computer places its sign in the [0,2] [1,1] [2,0] fields, it is a tie instead of the computer winning.

I think this is because those two if's give the same result
if board[rc][rc] != sgn: # check 1st diagonal cross1 = False if board[2 - rc][2 - rc] != sgn: # check 2nd diagonal cross2 = False
In my opinion, the function is better to look like this
` for rc in range(3):
if board[rc][0] == sign and board[rc][1] == sign and board[rc][2] == sign: # check row rc
return winner
if board[0][rc] == sign and board[1][rc] == sign and board[2][rc] == sign: # check column rc
return winner
if board[0][0] == sign and board[1][1] == sign and board[2][2] == sign:
return winner
if board[0][2] == sign and board[1][1] == sign and board[2][0] == sign:
return winner`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels