diff --git a/src/components/Board.tsx b/src/components/Board.tsx index d306fc7..7a9fc1c 100644 --- a/src/components/Board.tsx +++ b/src/components/Board.tsx @@ -1,5 +1,5 @@ import { FC, Fragment, useCallback, useEffect, useMemo, useState } from 'react'; -import { encodeFEN, eq, GameState } from '../utils/board'; +import { encodeFEN, eq, GameState, isChecked } from '../utils/board'; import { filterMoves, generateLegalMoves, @@ -91,10 +91,6 @@ const Board: FC = (props) => { const [promotionMove, setPromotionMove] = useState(null); - useEffect(() => { - console.log(currentState); - }, [currentState]); - const performMove = useCallback( (move: Move) => { const { board, enPassantTarget, sideToMove, castling } = makeMove( @@ -115,6 +111,14 @@ const Board: FC = (props) => { [currentState, setBoard, setSideToMove] ); + const gameResult = useMemo(() => { + if (validMoves.length === 0) { + const checked = isChecked(currentState) + return checked[sideToMove] ? 'checkmate' : 'stalemate'; + } + return false; + }, [validMoves, currentState, sideToMove]); + return ( <>