Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

a more memory efficient rewrite of the eval board in tictactoe (#3710)

JINO ROHIT1cae9956f405
diff --git a/camel/environments/tic_tac_toe.py b/camel/environments/tic_tac_toe.py
index 8ecca5b19..e11034fb1 100644
--- a/camel/environments/tic_tac_toe.py
+++ b/camel/environments/tic_tac_toe.py
@@ -413,6 +413,9 @@ class TicTacToeEnv(MultiStepEnv):
Args:
board (List[str]): The current game board as a list of strings.
is_x_turn (bool): True if it's X's turn to move, False otherwise.
+ depth (int): Current recursion depth. (default: :obj:`0`)
+ max_depth (int): Maximum recursion depth to prevent stack overflow.
+ (default: :obj:`10`)
Returns:
float: A float value representing the position evaluation:
@@ -435,14 +438,17 @@ class TicTacToeEnv(MultiStepEnv):
return 0.5 # Return draw evaluation at max depth
moves = TicTacToeEnv.available_moves(board)
+ if not moves:
+ return 0.5
+ symbol = "X" if is_x_turn else "O"
values = []
- # Create a copy of the board to avoid side effects
+
for move in moves:
- board_copy = board.copy()
- board_copy[move] = "X" if is_x_turn else "O"
+ board[move] = symbol
value = TicTacToeEnv.evaluate_position_for_x(
- board_copy, not is_x_turn, depth + 1, max_depth
+ board, not is_x_turn, depth + 1, max_depth
)
+ board[move] = " " # undo the move
values.append(value)
return max(values) if is_x_turn else min(values)