create_board
Create a custom-sized Minesweeper board by specifying width, height, and number of mines for gameplay.
Instructions
Create a new Minesweeper board with specified dimensions and mine count
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Unique identifier for the board | |
| width | Yes | Width of the board (number of columns) | |
| height | Yes | Height of the board (number of rows) | |
| mineCount | Yes | Number of mines to place on the board |
Implementation Reference
- src/index.ts:173-192 (handler)Handler for the 'create_board' tool call: extracts parameters, creates the board using MinesweeperGame, gets display, and returns formatted success response with legend.case 'create_board': { const { id, width, height, mineCount } = args as { id: string; width: number; height: number; mineCount: number; }; const board = this.game.createBoard(id, width, height, mineCount); const display = this.game.getBoardDisplay(id); return { content: [ { type: 'text', text: `Successfully created Minesweeper board '${id}'!\n\n${display}\n\nLegend:\n. = Hidden cell\nF = Flagged cell\n* = Mine (revealed)\n1-8 = Number of neighboring mines\n(space) = Empty cell with no neighboring mines`, }, ], }; }
- src/index.ts:49-79 (registration)Registration of the 'create_board' tool in the ListTools response, including name, description, and detailed input schema with validation.{ 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'], }, },
- src/minesweeper.ts:24-76 (helper)Core implementation of board creation: validates inputs, initializes grid, randomly places mines using generateMinePositions, computes neighbor mine counts, creates and stores GameBoard.createBoard(id: string, width: number, height: number, mineCount: number): GameBoard { if (width < 1 || height < 1) { throw new Error('Board dimensions must be at least 1x1'); } if (mineCount < 0 || mineCount >= width * height) { throw new Error('Mine count must be between 0 and total cells - 1'); } const cells: Cell[][] = []; // Initialize empty board for (let y = 0; y < height; y++) { cells[y] = []; for (let x = 0; x < width; x++) { cells[y][x] = { isMine: false, isRevealed: false, isFlagged: false, neighborMines: 0, x, y }; } } // Place mines randomly const minePositions = this.generateMinePositions(width, height, mineCount); for (const [x, y] of minePositions) { cells[y][x].isMine = true; } // Calculate neighbor mine counts for (let y = 0; y < height; y++) { for (let x = 0; x < width; x++) { if (!cells[y][x].isMine) { cells[y][x].neighborMines = this.countNeighborMines(cells, x, y, width, height); } } } const board: GameBoard = { id, width, height, mineCount, cells, gameState: 'playing', startTime: Date.now() }; this.boards.set(id, board); return board; }
- src/index.ts:52-78 (schema)Input schema for 'create_board' tool defining parameters with types, descriptions, constraints (min/max), and required fields.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'], },