diff --git a/.gitmodules b/.gitmodules index 588953b..93195f4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "verl"] path = verl - url = git@github.com:Agent-One-Lab/verl.git + url = https://github.com/Agent-One-Lab/verl.git diff --git a/src/agentfly/envs/chess_env.py b/src/agentfly/envs/chess_env.py index 43341fa..3c7e9c2 100644 --- a/src/agentfly/envs/chess_env.py +++ b/src/agentfly/envs/chess_env.py @@ -5,6 +5,7 @@ """ import asyncio +import shutil from typing import Any, Dict, List, Optional, Tuple, Union import chess @@ -13,6 +14,26 @@ from .env_base import BaseEnv +def _find_stockfish() -> str: + """Find the Stockfish binary on the system.""" + # Check common paths + common_paths = [ + "/usr/games/stockfish", # Ubuntu/Debian + "/usr/bin/stockfish", # Linux + "/opt/homebrew/bin/stockfish", # macOS (Homebrew ARM) + "/usr/local/bin/stockfish", # macOS (Homebrew Intel) + ] + for path in common_paths: + if shutil.which(path) or __import__('os').path.isfile(path): + return path + # Try to find in PATH + path = shutil.which("stockfish") + if path: + return path + # Default fallback + return "/opt/homebrew/bin/stockfish" + + class ChessPuzzleEnv(BaseEnv): """ Chess puzzle environment using python-chess and Stockfish. @@ -49,7 +70,7 @@ class ChessPuzzleEnv(BaseEnv): def __init__( self, - stockfish_path: str = "/opt/homebrew/bin/stockfish", + stockfish_path: str = None, analysis_time: float = 0.1, analysis_depth: int = 20, max_moves: int = 20, @@ -58,7 +79,7 @@ def __init__( Initialize the chess puzzle environment. Args: - stockfish_path: Path to the Stockfish binary. Common paths: + stockfish_path: Path to the Stockfish binary. If None, auto-detects. Common paths: - macOS (Homebrew): /opt/homebrew/bin/stockfish - Linux: /usr/bin/stockfish or /usr/games/stockfish - Windows: C:\\path\\to\\stockfish.exe @@ -67,7 +88,7 @@ def __init__( max_moves: Maximum number of moves allowed per puzzle """ super().__init__() - self.stockfish_path = stockfish_path + self.stockfish_path = stockfish_path or _find_stockfish() self.analysis_time = analysis_time self.analysis_depth = analysis_depth self.max_moves = max_moves diff --git a/tests/unit/envs/test_chess_env.py b/tests/unit/envs/test_chess_env.py index 33132f2..0c202af 100644 --- a/tests/unit/envs/test_chess_env.py +++ b/tests/unit/envs/test_chess_env.py @@ -7,6 +7,7 @@ """ import pytest +import pytest_asyncio from agentfly.envs.chess_env import ChessPuzzleEnv @@ -17,7 +18,7 @@ ) -@pytest.fixture +@pytest_asyncio.fixture async def chess_env(): """Create and start a chess environment for testing.""" env = ChessPuzzleEnv() @@ -171,7 +172,7 @@ async def test_puzzle_state_tracking(chess_env): puzzle = { "puzzle_id": "test", "fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", - "moves": "e2e4 e7e5 g1f3" # Multi-move puzzle + "moves": "e2e4 e7e5 g1f3" # Multi-move puzzle: e2e4 is setup, e7e5 is agent's move, g1f3 is response } await chess_env.reset(puzzle) @@ -183,11 +184,11 @@ async def test_puzzle_state_tracking(chess_env): # After setup, solution index should be 1 (first move was played) assert chess_env._current_solution_idx == 1 - # Make the correct move - await chess_env.step("e2e4") + # Make the correct move (e7e5, not e2e4 which was already auto-played as setup) + await chess_env.step("e7e5") assert len(chess_env.moves_made) == 1 - assert "e2e4" in chess_env.moves_made + assert "e7e5" in chess_env.moves_made @pytest.mark.asyncio