Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
27 changes: 24 additions & 3 deletions src/agentfly/envs/chess_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import asyncio
import shutil
from typing import Any, Dict, List, Optional, Tuple, Union

import chess
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/envs/test_chess_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import pytest
import pytest_asyncio
from agentfly.envs.chess_env import ChessPuzzleEnv


Expand All @@ -17,7 +18,7 @@
)


@pytest.fixture
@pytest_asyncio.fixture
async def chess_env():
"""Create and start a chess environment for testing."""
env = ChessPuzzleEnv()
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down