clear_region
Remove all puzzle tiles within a specified rectangular area to automatically solve that section of the level.
Instructions
Clear all tiles in a rectangular region. Auto-solves.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x1 | Yes | Top-left X | |
| y1 | Yes | Top-left Y | |
| x2 | Yes | Bottom-right X | |
| y2 | Yes | Bottom-right Y |
Implementation Reference
- src/tools/tile-operations.ts:159-175 (handler)The main handler function for clear_region tool. It gets the current draft, calculates the bounded rectangular region from x1,y1 to x2,y2, iterates through each position and calls draftStore.removeElement(), counts cleared positions, and returns a response with the count and auto-solved visualization.handler: async (args) => { const draft = draftStore.getCurrentDraft(); if (!draft) return { content: [{ type: 'text', text: 'No active draft. Use create_level first.' }] }; let cleared = 0; const minX = Math.max(1, Math.min(args.x1, args.x2)); const maxX = Math.min(draft.gridWidth - 2, Math.max(args.x1, args.x2)); const minY = Math.max(1, Math.min(args.y1, args.y2)); const maxY = Math.min(draft.gridHeight - 2, Math.max(args.y1, args.y2)); for (let y = minY; y <= maxY; y++) { for (let x = minX; x <= maxX; x++) { draftStore.removeElement(x, y); cleared++; } } const current = draftStore.getCurrentDraft()!; return { content: [{ type: 'text', text: `Cleared ${cleared} positions\n\n${autoSolveAndVisualize(current)}` }] }; },
- src/tools/tile-operations.ts:149-158 (schema)Input schema definition for clear_region tool. Defines an object with properties x1, y1, x2, y2 (all required numbers) representing the top-left and bottom-right coordinates of the rectangular region to clear.inputSchema: { type: 'object', properties: { x1: { type: 'number', description: 'Top-left X' }, y1: { type: 'number', description: 'Top-left Y' }, x2: { type: 'number', description: 'Bottom-right X' }, y2: { type: 'number', description: 'Bottom-right Y' }, }, required: ['x1', 'y1', 'x2', 'y2'], },
- src/tools/tile-operations.ts:147-176 (registration)Tool definition object for clear_region, including name, description, inputSchema, and handler. This is part of the array returned by getTileOperationTools() function that registers all tile operation tools.name: 'clear_region', description: 'Clear all tiles in a rectangular region. Auto-solves after clear.', inputSchema: { type: 'object', properties: { x1: { type: 'number', description: 'Top-left X' }, y1: { type: 'number', description: 'Top-left Y' }, x2: { type: 'number', description: 'Bottom-right X' }, y2: { type: 'number', description: 'Bottom-right Y' }, }, required: ['x1', 'y1', 'x2', 'y2'], }, handler: async (args) => { const draft = draftStore.getCurrentDraft(); if (!draft) return { content: [{ type: 'text', text: 'No active draft. Use create_level first.' }] }; let cleared = 0; const minX = Math.max(1, Math.min(args.x1, args.x2)); const maxX = Math.min(draft.gridWidth - 2, Math.max(args.x1, args.x2)); const minY = Math.max(1, Math.min(args.y1, args.y2)); const maxY = Math.min(draft.gridHeight - 2, Math.max(args.y1, args.y2)); for (let y = minY; y <= maxY; y++) { for (let x = minX; x <= maxX; x++) { draftStore.removeElement(x, y); cleared++; } } const current = draftStore.getCurrentDraft()!; return { content: [{ type: 'text', text: `Cleared ${cleared} positions\n\n${autoSolveAndVisualize(current)}` }] }; }, },
- src/tools/tile-operations.ts:14-24 (helper)Helper function autoSolveAndVisualize() used by the clear_region handler. It exports puzzle data, solves it, updates the draft with solver result, renders the level with coordinates, and returns a formatted string with the visualization and solver info.function autoSolveAndVisualize(draft: DraftState): string { const puzzleData = draftStore.exportPuzzleData(); if (puzzleData) { const result = solve(puzzleData); draftStore.updateDraft({ lastSolverResult: result, isDirty: false }); } const current = draftStore.getCurrentDraft()!; const viz = renderLevel(current, { showCoords: true }); const solverInfo = current.lastSolverResult ? formatSolverResult(current.lastSolverResult) : ''; return `${viz}\n${solverInfo}`; }