There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
How long does the recursive function in part 1 normally take to run? Mine seems to have been running for quite a while, which I guess is normal for recursive sometimes, and I feel like I shouldn’t be in a infinity loop.
Hi, Can someone explain how the second minimax() function gets executed inside the “for move” loop?
I don’t get how minimax(new_board, not is_maximizing) is executed while being in the “for move” loop. What’s the “hypothetical_value” value? It seems to me like it should be infinite loop
def minimax(input_board, is_maximizing):
# Base case - the game is over, so we return the value of the board
if game_is_over(input_board):
return evaluate_board(input_board)
if is_maximizing == True:
best_value = -float("Inf")
symbol = "X"
else:
best_value = float("Inf")
symbol = "O"
for move in available_moves(input_board): #list possible moves
new_board = deepcopy(input_board) #create a new board to track changes
select_space(new_board, move, symbol)#make a hypothetical move
hypothetical_value=minimax(new_board, not is_maximizing)#2nd move gain?
if is_maximizing==True:
if hypothetical_value>best_value:
best_value=hypothetical_value
elif is_maximizing==False:
if hypothetical_value<best_value:
best_value=hypothetical_value
return best_value
It doesn’t end in an infinite loop because we know it will eventually get to a resolution of the game so we will force it to get to the first if statement in the function and return a value there that will then work it’s way back up the calls.