Skip to content

Fix: Pawns on edge ranks should have no chess.moves()#578

Open
some1else wants to merge 2 commits into
jhlywa:masterfrom
some1else:some1else/move-big-int
Open

Fix: Pawns on edge ranks should have no chess.moves()#578
some1else wants to merge 2 commits into
jhlywa:masterfrom
some1else:some1else/move-big-int

Conversation

@some1else
Copy link
Copy Markdown

@some1else some1else commented Jan 17, 2026

Closes #577

Pawn on H8 throws a BigInt error when asked about chess.moves({ square: 'h8' })

TypeError: Cannot mix BigInt and other types, use explicit conversions
    at Chess._movePiece (/app/node_modules/src/chess.ts:1737:24)
    at Chess._makeMove (/app/node_modules/src/chess.ts:1764:10)
    at Chess._moveToSan (/app/node_modules/src/chess.ts:2279:10)
    at new Move (/app/node_modules/src/chess.ts:160:35)
    at /app/node_modules/src/chess.ts:1452:34
    at Array.map (<anonymous>)
    at Chess.moves (/app/node_modules/src/chess.ts:1452:20)

@some1else some1else changed the title Pawns on edge ranks should have no chess.moves() Fix: Pawns on edge ranks should have no chess.moves() Jan 17, 2026
@some1else some1else force-pushed the some1else/move-big-int branch from 98f7eb5 to 9bb38a3 Compare January 17, 2026 06:05
@neofight78
Copy link
Copy Markdown
Collaborator

I'm not sure whether to merge this yet, as a pawn on h8 is not a legal position. It maybe better to tighten up / change the way the board can be set up.

@some1else
Copy link
Copy Markdown
Author

some1else commented Jan 17, 2026

Depends on how strictly you'd like to lock the library down to modern chess rules. There are fringe regimes such as the British Chess Association "dead pawn" rule, and the Burmese Chess promotion rules, under which a pawn can legally occupy the promotion square: https://en.wikipedia.org/wiki/Promotion_%28chess%29

You'll want to reconcile the chosen policy with { skipValidation: true } options for the constructor, as that is likely another code path through which it's possible to place a pawn there.

I'm prototyping a rules-free software chess set mimicking a physical board & pieces, where it's in line with the concept to allow such positions: https://shah-baby.netlify.app. It'd be nice if I could still use chess.js for state management.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigInt error when generating moves for pawns on edge ranks

2 participants