willb335 / chessboardjsx

:black_square_button: Chessboard built for React
https://chessboardjsx.com
MIT License
267 stars 79 forks source link

How to get FEN? #51

Open rilmasaker opened 4 years ago

rilmasaker commented 4 years ago

getPosition () gives us only position object, how to get to position FEN. For example, can you add the second argument getPosition function (objPostion: object, fenPosition: string) => void?

jantznick commented 4 years ago

Board state.currentPosition lists where all the pieces are, this could be looped over to get the current FEN notation. I can work on it for a future PR.

szpakowski commented 4 years ago

Is a .fen() type method even necessary? You supplying the fen or position object and the fen can easily be obtained from chessboard.js. https://chessboardjs.com/examples#3000

danbockapps commented 3 years ago

I think this is one of those features that is best left to chess.js. Create a chess.js object and update it in the onDrop function that you pass to Chessboard by calling chess.move({ from: sourceSquare, to: targetSquare }) and then you can call chess.fen() to get the FEN. You can see an example here: https://github.com/willb335/chessboardjsx/blob/master/src/integrations/WithMoveValidation.js

HikeGrig commented 3 years ago

I found solution. I used fen-chess-board and wrote a little bit code to match the position formats. Here is example: https://codesandbox.io/s/funny-williams-q26ku?file=/src/Demo.js