reveal_cell
Reveal a cell on a Minesweeper board to check for mines or clear safe areas. Specify board ID and coordinates to interact with the game.
Instructions
Reveal a cell on the Minesweeper board
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| boardId | Yes | ID of the board | |
| x | Yes | X coordinate (column) of the cell to reveal | |
| y | Yes | Y coordinate (row) of the cell to reveal |
Implementation Reference
- src/minesweeper.ts:113-155 (handler)Core implementation of revealCell: validates input, handles mine revelation (loss), recursive reveal for safe cells, checks win condition, updates game state.revealCell(boardId: string, x: number, y: number): GameBoard { const board = this.boards.get(boardId); if (!board) { throw new Error(`Board with id ${boardId} not found`); } if (board.gameState !== 'playing') { throw new Error('Game is already finished'); } if (x < 0 || x >= board.width || y < 0 || y >= board.height) { throw new Error('Invalid cell coordinates'); } const cell = board.cells[y][x]; if (cell.isRevealed || cell.isFlagged) { return board; // Already revealed or flagged } if (cell.isMine) { // Game over cell.isRevealed = true; board.gameState = 'lost'; board.endTime = Date.now(); // Reveal all mines for (let row of board.cells) { for (let c of row) { if (c.isMine) { c.isRevealed = true; } } } } else { // Reveal cell and potentially cascade this.revealCellRecursive(board, x, y); // Check win condition if (this.checkWinCondition(board)) { board.gameState = 'won'; board.endTime = Date.now(); } } return board; }
- src/minesweeper.ts:157-174 (helper)Recursive helper function that reveals adjacent safe empty cells (flood fill).private revealCellRecursive(board: GameBoard, x: number, y: number): void { if (x < 0 || x >= board.width || y < 0 || y >= board.height) return; const cell = board.cells[y][x]; if (cell.isRevealed || cell.isFlagged || cell.isMine) return; cell.isRevealed = true; // If cell has no neighboring mines, reveal all neighbors if (cell.neighborMines === 0) { for (let dy = -1; dy <= 1; dy++) { for (let dx = -1; dx <= 1; dx++) { if (dx === 0 && dy === 0) continue; this.revealCellRecursive(board, x + dx, y + dy); } } } }
- src/index.ts:81-103 (schema)Input schema definition for the reveal_cell tool, including parameters boardId, x, y.name: 'reveal_cell', description: 'Reveal a cell on the Minesweeper board', inputSchema: { type: 'object', properties: { boardId: { type: 'string', description: 'ID of the board', }, x: { type: 'number', description: 'X coordinate (column) of the cell to reveal', minimum: 0, }, y: { type: 'number', description: 'Y coordinate (row) of the cell to reveal', minimum: 0, }, }, required: ['boardId', 'x', 'y'], }, },
- src/index.ts:46-166 (registration)Registration of tools list including reveal_cell via setRequestHandler for ListToolsRequestSchema.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'create_board', description: 'Create a new Minesweeper board with specified dimensions and mine count', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'Unique identifier for the board', }, width: { type: 'number', description: 'Width of the board (number of columns)', minimum: 1, maximum: 50, }, height: { type: 'number', description: 'Height of the board (number of rows)', minimum: 1, maximum: 50, }, mineCount: { type: 'number', description: 'Number of mines to place on the board', minimum: 0, }, }, required: ['id', 'width', 'height', 'mineCount'], }, }, { name: 'reveal_cell', description: 'Reveal a cell on the Minesweeper board', inputSchema: { type: 'object', properties: { boardId: { type: 'string', description: 'ID of the board', }, x: { type: 'number', description: 'X coordinate (column) of the cell to reveal', minimum: 0, }, y: { type: 'number', description: 'Y coordinate (row) of the cell to reveal', minimum: 0, }, }, required: ['boardId', 'x', 'y'], }, }, { name: 'flag_cell', description: 'Flag or unflag a cell on the Minesweeper board', inputSchema: { type: 'object', properties: { boardId: { type: 'string', description: 'ID of the board', }, x: { type: 'number', description: 'X coordinate (column) of the cell to flag', minimum: 0, }, y: { type: 'number', description: 'Y coordinate (row) of the cell to flag', minimum: 0, }, }, required: ['boardId', 'x', 'y'], }, }, { name: 'get_board', description: 'Get the current state and visual representation of a Minesweeper board', inputSchema: { type: 'object', properties: { boardId: { type: 'string', description: 'ID of the board to display', }, }, required: ['boardId'], }, }, { name: 'list_boards', description: 'List all active Minesweeper boards', inputSchema: { type: 'object', properties: {}, }, }, { name: 'delete_board', description: 'Delete a Minesweeper board', inputSchema: { type: 'object', properties: { boardId: { type: 'string', description: 'ID of the board to delete', }, }, required: ['boardId'], }, }, ] as Tool[], }; });
- src/index.ts:194-221 (handler)MCP tool call handler for reveal_cell: parses arguments, calls game.revealCell, formats response with board display and game status.case 'reveal_cell': { const { boardId, x, y } = args as { boardId: string; x: number; y: number; }; const board = this.game.revealCell(boardId, x, y); const display = this.game.getBoardDisplay(boardId); let message = `Revealed cell at (${x}, ${y})\n\n${display}`; if (board.gameState === 'won') { const duration = board.endTime ? Math.round((board.endTime - board.startTime) / 1000) : 0; message += `\nš Congratulations! You won in ${duration} seconds!`; } else if (board.gameState === 'lost') { message += `\nš„ Game Over! You hit a mine at (${x}, ${y}).`; } return { content: [ { type: 'text', text: message, }, ], }; }