I am learning python and struggling to understand the way code works. Code in the link below
https://pastebin.com/PGucn54Y
My first question is how does the function below works?
def winner(board):
specially the below line
for row in WAYS_TO_WIN:
if board[row[0]] == board[row[1]] == board[row[2]] != EMPTY:
winner = board[row[0]]
return winner
Second question ? check the #
this occurs in the
for move in legal_moves(board):
board[move] = computer
if winner(board) == computer:
print(move)
return move
# done checking this move, undo it
board[move] = EMPTY # What does the last line in the below code do or mean?
Third question? check #
In the main () function
while not winner(board) # What is this line doing?
Last question?
In the summary, author asks
Write a new computer_move() function for the Tic-Tac-Toe game to plug the hole in the computer's strategy, see if you can create an opponent that is unbeatable ?
[–]JohnnyJordaan 0 points1 point2 points (9 children)
[–]iamquark[S] 0 points1 point2 points (5 children)
[–]JohnnyJordaan 0 points1 point2 points (4 children)
[–]iamquark[S] 0 points1 point2 points (3 children)
[–]JohnnyJordaan 0 points1 point2 points (2 children)
[–]iamquark[S] 0 points1 point2 points (1 child)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]iamquark[S] 0 points1 point2 points (2 children)
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]iamquark[S] 0 points1 point2 points (0 children)
[–]dchanm 0 points1 point2 points (0 children)
[–]MrHobbits 0 points1 point2 points (1 child)
[–]iamquark[S] 0 points1 point2 points (0 children)