Skip to content

Commit fbda28a

Browse files
Copilotmgierschdev
andcommitted
Add captured pieces display to UI
Co-authored-by: mgierschdev <62764972+mgierschdev@users.noreply.github.com>
1 parent d8f4fdb commit fbda28a

File tree

2 files changed

+75
-6
lines changed

2 files changed

+75
-6
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use client';
2+
3+
import React from 'react';
4+
import {ChessPiece} from "@/app/_models/ChessPiece";
5+
6+
interface CapturedPiecesProps {
7+
pieces: ChessPiece[];
8+
color: 'White' | 'Black';
9+
}
10+
11+
export default function CapturedPieces({pieces, color}: CapturedPiecesProps) {
12+
if (!pieces || pieces.length === 0) {
13+
return <div style={{ fontSize: '14px', color: '#666' }}>None</div>;
14+
}
15+
16+
// Count pieces by type
17+
const pieceCounts: { [key: string]: number } = {};
18+
pieces.forEach(piece => {
19+
if (piece.type && piece.type !== 'Empty' && piece.type !== 'Invalid') {
20+
pieceCounts[piece.type] = (pieceCounts[piece.type] || 0) + 1;
21+
}
22+
});
23+
24+
// Map piece types to symbols (Unicode chess pieces)
25+
const pieceSymbols: { [key: string]: string } = {
26+
'Pawn': color === 'White' ? '♙' : '♟',
27+
'Knight': color === 'White' ? '♘' : '♞',
28+
'Bishop': color === 'White' ? '♗' : '♝',
29+
'Rook': color === 'White' ? '♖' : '♜',
30+
'Queen': color === 'White' ? '♕' : '♛',
31+
'King': color === 'White' ? '♔' : '♚'
32+
};
33+
34+
return (
35+
<div style={{
36+
display: 'flex',
37+
flexWrap: 'wrap',
38+
gap: '4px',
39+
fontSize: '24px',
40+
minHeight: '30px',
41+
alignItems: 'center'
42+
}}>
43+
{Object.entries(pieceCounts).map(([type, count]) => (
44+
<div key={type} style={{ display: 'flex', alignItems: 'center' }}>
45+
{Array.from({ length: count }).map((_, index) => (
46+
<span
47+
key={`${type}-${index}`}
48+
style={{
49+
marginRight: '2px',
50+
filter: color === 'White' ? 'invert(1)' : 'none'
51+
}}
52+
>
53+
{pieceSymbols[type] || ''}
54+
</span>
55+
))}
56+
</div>
57+
))}
58+
</div>
59+
);
60+
}

frontend/src/app/_client_components/RightSidePanel.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {ChessService} from "@/app/_services/ChessService";
55
import {ChessGame} from "@/app/_models/ChessGame";
66
import {GameState} from "@/app/_models/enums";
77
import MoveHistory from "./MoveHistory";
8+
import CapturedPieces from "./CapturedPieces";
89

910
// Game Service
1011
let gameService: ChessService = new ChessService();
@@ -74,14 +75,22 @@ export default function RightSidePanel({gameInfoProp, onBotModeChange, onGameInf
7475
<MoveHistory moves={gameInfo.moveHistory || []} />
7576
</div>
7677

77-
<div
78-
className="right-side-panel-item">
79-
Black Pieces:
78+
<div className="right-side-panel-item" style={{ marginTop: '20px' }}>
79+
<strong>Captured Pieces</strong>
8080
</div>
8181

82-
<div
83-
className="right-side-panel-item">
84-
White Pieces:
82+
<div className="right-side-panel-item" style={{ marginTop: '10px' }}>
83+
<div style={{ marginBottom: '5px', fontSize: '14px', fontWeight: 'bold' }}>
84+
Black Pieces:
85+
</div>
86+
<CapturedPieces pieces={gameInfo.capturedBlack || []} color="Black" />
87+
</div>
88+
89+
<div className="right-side-panel-item" style={{ marginTop: '10px' }}>
90+
<div style={{ marginBottom: '5px', fontSize: '14px', fontWeight: 'bold' }}>
91+
White Pieces:
92+
</div>
93+
<CapturedPieces pieces={gameInfo.capturedWhite || []} color="White" />
8594
</div>
8695
</div>
8796
);

0 commit comments

Comments
 (0)