diff --git a/src/components/ChessGame.tsx b/src/components/ChessGame.tsx index a93c4d6..4edbe2c 100644 --- a/src/components/ChessGame.tsx +++ b/src/components/ChessGame.tsx @@ -85,10 +85,8 @@ export default function ChessGame({ initialFen, initialPgn, initialPersonality, } }; - // Scroll to bottom of move history - useEffect(() => { - messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); - }, [moveHistory]); + // Removed auto-scroll to prevent page jumping when moves are added + // Users can manually scroll to see move history if needed // Captured Pieces State const [capturedWhitePieces, setCapturedWhitePieces] = useState([]); @@ -544,32 +542,52 @@ export default function ChessGame({ initialFen, initialPgn, initialPersonality, # White Black + Eval Δ - {(() => { - const history = gameRef.current.history(); - const rows = []; - for (let i = 0; i < history.length; i += 2) { - rows.push( - - {Math.floor(i / 2) + 1}. - {history[i]} - {history[i + 1] || ""} - - ); - } - if (rows.length === 0) { + {moveHistory.length === 0 ? ( + + + No moves yet. + + + ) : ( + moveHistory.map((item, idx) => { + // Calculate evaluation change for player's move + const evalBefore = item.evalBeforePlayerMove.score ?? 0; + const evalAfter = item.evalAfterPlayerMove.score ?? 0; + const evalChange = evalAfter - evalBefore; + + // Determine color based on evaluation change + // Positive change = good for white, negative = good for black + let evalColor = 'text-gray-500'; + if (Math.abs(evalChange) > 50) { + if (item.playerColor === 'white') { + evalColor = evalChange > 0 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'; + } else { + evalColor = evalChange < 0 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'; + } + } + + const evalDisplay = evalChange > 0 ? `+${(evalChange / 100).toFixed(1)}` : (evalChange / 100).toFixed(1); + return ( - - - No moves yet. + + {item.moveNumber}. + + {item.playerColor === 'white' ? item.playerMove : item.computerMove} + + + {item.playerColor === 'black' ? item.playerMove : item.computerMove} + + + {evalDisplay} ); - } - return rows; - })()} + }) + )}