Closed fabthegreat closed 1 year ago
Hey,
you could register a afterMoveCallback function and then get the last move from the lichess chessground.
<script setup lang="ts">
import { ref, toRaw } from 'vue';
import { TheChessboard, type ChessboardAPI, type BoardConfig } from '@/index';
import '@/assets/board.css';
const boardAPI = ref<ChessboardAPI>();
function afterMove() {
console.log(toRaw(boardAPI.value?.board.state.lastMove));
}
const boardConfig: BoardConfig = {
coordinates: true,
autoCastle: false,
};
</script>
<template>
<main>
<TheChessboard
:board-config="boardConfig"
:after-move-cb="afterMove"
@board-created="(api) => (boardAPI = api)"
/>
</main>
</template>
Output:
Array [ "e2", "e4" ]
Please let me know if this works for you.
I will probably add some more methods to the boardapi in the next version, including a method to get the last move easier and with more information.
Thanks for your answer! I finally coded my chessboard from scratch ;) but it is far less good looking than yours for the moment! For now my main concern is about the possible moves on the board, it works based on chessjs lib but it takes a huge amount of time (something like 180ms for a Queen with many possible moves). It is related to the chessjs lib itself, maybe I'll give a try with another one.
I also use chess.js to generate the possibles moves. Its working fine.
Im going to close this for now...
Hi, great job! Is there a way to retrieve a move (whatever the format) once it has been played?
Thanks