55"""
66
77import asyncio
8+ import shutil
89from typing import Any , Dict , List , Optional , Tuple , Union
910
1011import chess
1314from .env_base import BaseEnv
1415
1516
17+ def _find_stockfish () -> str :
18+ """Find the Stockfish binary on the system."""
19+ # Check common paths
20+ common_paths = [
21+ "/usr/games/stockfish" , # Ubuntu/Debian
22+ "/usr/bin/stockfish" , # Linux
23+ "/opt/homebrew/bin/stockfish" , # macOS (Homebrew ARM)
24+ "/usr/local/bin/stockfish" , # macOS (Homebrew Intel)
25+ ]
26+ for path in common_paths :
27+ if shutil .which (path ) or __import__ ('os' ).path .isfile (path ):
28+ return path
29+ # Try to find in PATH
30+ path = shutil .which ("stockfish" )
31+ if path :
32+ return path
33+ # Default fallback
34+ return "/opt/homebrew/bin/stockfish"
35+
36+
1637class ChessPuzzleEnv (BaseEnv ):
1738 """
1839 Chess puzzle environment using python-chess and Stockfish.
@@ -49,7 +70,7 @@ class ChessPuzzleEnv(BaseEnv):
4970
5071 def __init__ (
5172 self ,
52- stockfish_path : str = "/opt/homebrew/bin/stockfish" ,
73+ stockfish_path : str = None ,
5374 analysis_time : float = 0.1 ,
5475 analysis_depth : int = 20 ,
5576 max_moves : int = 20 ,
@@ -58,7 +79,7 @@ def __init__(
5879 Initialize the chess puzzle environment.
5980
6081 Args:
61- stockfish_path: Path to the Stockfish binary. Common paths:
82+ stockfish_path: Path to the Stockfish binary. If None, auto-detects. Common paths:
6283 - macOS (Homebrew): /opt/homebrew/bin/stockfish
6384 - Linux: /usr/bin/stockfish or /usr/games/stockfish
6485 - Windows: C:\\ path\\ to\\ stockfish.exe
@@ -67,7 +88,7 @@ def __init__(
6788 max_moves: Maximum number of moves allowed per puzzle
6889 """
6990 super ().__init__ ()
70- self .stockfish_path = stockfish_path
91+ self .stockfish_path = stockfish_path or _find_stockfish ()
7192 self .analysis_time = analysis_time
7293 self .analysis_depth = analysis_depth
7394 self .max_moves = max_moves
0 commit comments