lichess-org / chessground

Mobile/Web chess UI for lichess.org
https://lichess.org
GNU General Public License v3.0
1.02k stars 262 forks source link

Automatic pawn promotion #209

Closed victorocna closed 2 years ago

victorocna commented 2 years ago

Hello everyone!

I was wondering if it's possible to promote a pawn into any other piece. From the API I noticed that chess.move() takes only orig and dest parameters. Is there any way to pass the new piece a pawn is promoted to?

Cheers, Victor

ornicar commented 2 years ago

you can use https://github.com/ornicar/chessground/blob/master/src/api.ts#L30

victorocna commented 2 years ago

can you please give me an example of setPieces usage in javascript?

victorocna commented 2 years ago

Figured it out. An example for posterity below:

setPieces({ a8: { role: 'queen', color: 'white', promoted: true } });

The only problem is that now the pawn that should be promoted does not disappear from the board.

niklasf commented 2 years ago

Include a7: null. Or alternatively just set({fen}), and let chessground compute the incremental update.