File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -413,6 +413,9 @@ def evaluate_position_for_x(
413413 Args:
414414 board (List[str]): The current game board as a list of strings.
415415 is_x_turn (bool): True if it's X's turn to move, False otherwise.
416+ depth (int): Current recursion depth. (default: :obj:`0`)
417+ max_depth (int): Maximum recursion depth to prevent stack overflow.
418+ (default: :obj:`10`)
416419
417420 Returns:
418421 float: A float value representing the position evaluation:
@@ -435,14 +438,17 @@ def evaluate_position_for_x(
435438 return 0.5 # Return draw evaluation at max depth
436439
437440 moves = TicTacToeEnv .available_moves (board )
441+ if not moves :
442+ return 0.5
443+ symbol = "X" if is_x_turn else "O"
438444 values = []
439- # Create a copy of the board to avoid side effects
445+
440446 for move in moves :
441- board_copy = board .copy ()
442- board_copy [move ] = "X" if is_x_turn else "O"
447+ board [move ] = symbol
443448 value = TicTacToeEnv .evaluate_position_for_x (
444- board_copy , not is_x_turn , depth + 1 , max_depth
449+ board , not is_x_turn , depth + 1 , max_depth
445450 )
451+ board [move ] = " " # undo the move
446452 values .append (value )
447453
448454 return max (values ) if is_x_turn else min (values )
You can’t perform that action at this time.
0 commit comments