Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the from and to square from SAN? #462

Open
ahofmeister opened this issue May 31, 2024 · 1 comment
Open

How to get the from and to square from SAN? #462

ahofmeister opened this issue May 31, 2024 · 1 comment

Comments

@ahofmeister
Copy link

We want to draw an error for a specific move, that is part of a puzzle. For example, the user should play e4 , but played d4. We now want to display an error from d2 to d4. We only have the SAN (d4 in this case) available.

A possible solution could be, that we create a temporary game, execute the move with the SAN and get the move back. Not sure how this is performance wise.

Do you have any other solution on how to get the from and to square, to draw an arrow only from the SAN?

@ahofmeister
Copy link
Author

I can confirm the solution I have suggested

  const showArrowForCorrectMove = (currentLine: TreeNode[]) => {
    const tempGame = new Chess(game.fen());
    const move = tempGame.move(currentLine?.[heroMoveIndex]?.move);
    if (move) {
      setCorrectMoveArrow([move?.from, move?.to, getRedColor().hexCode]);
    }
  };

The SAN comes from currentLine?.[heroMoveIndex]?.move and the game.fen() is the "main" game. Don't worry about the rest. :)

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

No branches or pull requests

1 participant