Skip to content

incorrect tie project - tic-tac-toe sample answer.py #1

@aulemasa

Description

@aulemasa

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.
tie

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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions