ajax333221 / isepic-chess

♞ JavaScript chess utility library.
MIT License
16 stars 3 forks source link

The "isMockMove" option from board.playMove() doesn't preserve board.promoteTo #10

Closed ajax333221 closed 3 years ago

ajax333221 commented 3 years ago

The cause of the bug lies in that isMockMove=true creates a temporal board in fenApply() which by default the promoteTo is set to Queen.

When using Ic.fenApply(fen, "playMove", [...]), it becomes clear that the temporal board will default to Queen unless a promoteTo option is passed. But when using board.playMove("...", {isMockMove : true}) it is expected that it will use the current board.promoteTo by default when a promoteTo option is not passed.

The severity of the bug is low as it doesn't impact anything for parsing or validation, and only gives unexpected behavior to anyone manually using it in this specific edge scenario.

Note to self: the solution could be give fenApply its own p options: Ic.fenApply(fen, "playMove", [..., p], p), the users calling playMove via fenApply will not need to change anything or pass any extra parameter, and the users calling playMove via board.playMove() would not need to change anything or pass any extra parameter. The change will be internally and the API would be unaffected, but the bug should be gone after this.