Skip to content

Conversation

@joachimbulow
Copy link

@joachimbulow joachimbulow commented Sep 21, 2025

Moved stateful function into chess class

Having state manipulating functionality exported and separate from the chess class seems like it breaks the general structure of having state-less util-like functions exported outside of the chess class.

The function is not part of the public api - so should be a minor change

src/chess.ts Outdated
) {
const r = rank(to)

if (piece === PAWN && ((color === BLACK && r === RANK_1) || (color === WHITE && r === RANK_8))) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now check color + rank as opposed to just checking ranks

@neofight78
Copy link
Collaborator

The changes / tests are unnecessary, as a white pawn can never move to the first rank, and a black pawn can never to move to the eighth rank.

@joachimbulow
Copy link
Author

Right - I am looking to extend the system to allow for more rules - which is what led me to that change.
For a static chess engine like this one, the infererred logic is just fine.

I have edited the description and removed the redundant check.

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.

2 participants