You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After the board is filled in the Tic Tac Toe game, the program crashes with an error:
TypeError: list indices must be integers or slices, not NoneType
Cause:
The compMove() function returns None when no moves are left, but the program tries to insert at board[None].
Suggested Solution:
Before calling insertLetter("O", move), check if move is None and handle it as a tie.
Example:
if move == 0 or move is None:
print("Tie game")
else:
insertLetter("O", move)
print(f"Computer placed O on position {move}")
printBoard(board)
Additional Suggestion:
In compMove(), add a check:
if len(possibleMoves) == 0:
return None
Happy to work on fixing this if you would like! 🚀
The text was updated successfully, but these errors were encountered:
Apache-R
added a commit
to Apache-R/Python-Projects
that referenced
this issue
May 23, 2025
After the board is filled in the Tic Tac Toe game, the program crashes with an error:
TypeError: list indices must be integers or slices, not NoneType
Cause:
The compMove() function returns None when no moves are left, but the program tries to insert at board[None].
Suggested Solution:
Before calling insertLetter("O", move), check if move is None and handle it as a tie.
Example:
if move == 0 or move is None:
print("Tie game")
else:
insertLetter("O", move)
print(f"Computer placed O on position {move}")
printBoard(board)
Additional Suggestion:
In compMove(), add a check:
if len(possibleMoves) == 0:
return None
Happy to work on fixing this if you would like! 🚀
The text was updated successfully, but these errors were encountered: