def afterGame(board):
global gamerunning, winner, currentPlayer
winner = currentPlayer
winning_line = None
winning_combinations = [
[0, 1, 2], [3, 4, 5], [6, 7, 8],
[0, 3, 6], [1, 4, 7], [2, 5, 8],
[0, 4, 8], [2, 4, 6]
]
for line in winning_combinations:
if board[line[0]] == board[line[1]] == board[line[2]] != "-":
winning_line = line
break```
its working and i know ishould not touch it but i dont really understand the loop i build here why do i use those specific numbers and not 3,4,5 for example
#๐ can some explain this code to me
9 messages ยท Page 1 of 1 (latest)
@burnt kayak
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
Because those are the indices of a tic tac toe grid that represent a winning position
those "winning combinations" are just indexes of horizontal, vertical and diagonal lines on a 3 by 3 matrix as shown in the picture
so what this loop does is to iterate over all the lines of the board and check if they have the same symbol (x or O)
@burnt kayak
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.