The chess application now supports two game modes:
- Human vs Human - Two players take turns
- Human vs Computer - Player (White) vs AI Bot (Black)
- Navigate to the chess game
- Locate the "Play vs Computer" checkbox on the right panel
- Check the box to enable bot mode
- Start a new game
- When bot mode is enabled, you play as White
- The computer plays as Black
- After you make your move, the AI automatically calculates and plays its response
- You'll see a "Computer is thinking..." indicator while the AI computes its move
- The AI uses the backend
/aiMoveendpoint to calculate best moves
- Simply uncheck the "Play vs Computer" checkbox to return to human vs human mode
-
ChessService.tsx
- Added
getAIMove()method that calls the backend/aiMoveendpoint - Parses the AI response format:
fromRow,fromCol,toRow,toCol,score
- Added
-
RightSidePanel.tsx
- Added checkbox for toggling bot mode
- Added
onBotModeChangecallback prop - Checkbox has
data-testid="bot-mode-toggle"for testing
-
Chessboard.tsx
- Added
isBotModeprop - Added
isComputerThinkingstate - Automatically triggers AI move after player's move when in bot mode
- Displays "Computer is thinking..." indicator
- Prevents player moves while computer is calculating
- Added
-
ChessGameWrapper.tsx (new)
- Client component wrapper that manages bot mode state
- Passes bot mode state to both Chessboard and RightSidePanel
-
page.tsx
- Updated to use ChessGameWrapper instead of direct components
The bot mode uses the existing /aiMove endpoint:
- GET
/aiMove - Returns:
{id: number, content: string}where content is"row,col,row,col,score" - The AI analyzes the current game state and returns the best move
Bot Mode Tests (chess-bot-mode.test.ts):
-
Visual Verification Test - Plays 3 moves against the bot with screenshots
- Verifies bot mode can be enabled
- Makes player moves and waits for AI responses
- Captures screenshots after each player and computer move
- Total of 11 screenshots showing complete interaction
-
Toggle Test - Verifies the checkbox works correctly
- Checks/unchecks the bot mode toggle
- Verifies state changes
- Start the application
- Enable "Play vs Computer"
- Start a new game
- Make a move (e.g., e2-e4)
- Observe the AI's response
- Continue playing to verify the game flow
Screenshots from the automated test show:
- Bot mode checkbox enabled
- Player making moves
- "Computer is thinking..." indicator
- AI responses on the board
- Complete game progression
All screenshots are saved in e2e-tests/test-results/bot-screenshots/