Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Opening lookup by moves - #44

Merged
JeffML merged 6 commits into
omuryanikoglu:masterfrom
JeffML:master
Dec 10, 2025
Merged

JeffML merged 6 commits into
omuryanikoglu:masterfrom
JeffML:master

Conversation

@JeffML

@JeffML JeffML commented Dec 10, 2025

Copy link
Copy Markdown
Collaborator

Some PGN files lack moves, or have less specific variation names than what is in eco.json. This new feature will find an eco.json variation based on the moves of a game. This uses a dependency injection pattern for the chess engine that is needed to navigate moves and derive FEN from position.

- New lookupByMoves() function walks backward through move history
- Works with any chess library via ChessGameLike interface
- Compatible with chess.js, @chess-pgn/chess-pgn, and similar libraries
- Returns opening and number of moves walked back
- Includes comprehensive JSDoc and examples
- Updates README with full documentation and examples
- Move lookupByMoves from separate file into methods/findOpening.ts
- Simplify ChessGameLike interface (remove history() requirement)
- Change undo() return type to 'unknown' for maximum compatibility
- Update exports in src/index.ts
- Update README documentation
- All tests pass, example verified working
- Default maxMovesBack changed from unlimited to 50 plies
- Parse FEN to calculate current ply without undoing all moves
- Skip directly to ply 50 for longer games before walking backward
- Prevents unnecessary search beyond typical opening theory
- Still allows override via maxMovesBack option
@JeffML
JeffML merged commit 1e3cb67 into omuryanikoglu:master Dec 10, 2025
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant