use single tab indent. do not add useless comments, only necessary. write clean…
- User
use single tab indent. do not add useless comments, only necessary. write clean efficient code, prefer inline js in html. camel_case.
without redundant checks, assume data is correct and better if function crash to expose data errors.
central area array choose w,h monospace font choose size each cell is symbol
can set cursor to select cell press keyboard or letters storage to replacing content. Example: click, press asdf wil result "f" in cell
Bottom area statistics number used letters available letters checkbox limit. if checked then type from available storage. checkbox reuse. if checked then replaced letters return to storage letter storage list of available letters with available quantity. count of total changes in game area. cells in storage also have hovered event to show info. slider game speed FPS
right area info about hovered cell and letter inside it.
letters info: x wall o item ball movable, fall down if no wall. only 1 ball in cell . item particle movable, can move to other particle to form particles : item particles randomly turn into 1 particle. 10% chance
right (wall) < left (wall) >o_ >_o ^ up (wall) v down (wall) = teleport each frame swap cells right and left to it ( a=b b=a ) i heat (wall) each frame add heat to near items. untill 255. ball with 255 heat became particle. heat is Red color amount. f cold (wall) cool near items
9 sink delete items in near cells
- source create particles in random free near cells
each frame swap buffers (we read one write to other)
<^v push o and : probably better not actually push but set item property move 1 in that direction. so next turn item propagate movement property or move itself and clear movement flag. o and : has property of it moving direction to propagate pushing to adjacent o: think how to easy propagate movement without loops, recursion, races. each frame movement propagate until there is obstacle. do not use loops in calculate movement. use iterative simulation approach.
gray grid lines render items: 255, 255-heat, 255-heat
Assistant
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Grid Game</title> <style> body { margin: 0; font-family: monospace; background: #222; color: white; } #game { display: grid; gap: 1px; background: #444; } .cell { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; user-select: none; } .cell:hover { background: #555; } #ui { display: flex; height: 100vh; } #main { flex: 1; display: flex; flex-direction: column; } #stats { padding: 8px; background: #333; } #info { width: 200px; padding: 8px; background: #333; } input[type="range"] { width: 100%; } </style> </head> <body> <div id="ui"> <div id="main"> <div id="game"></div> <div id="stats"> <div>Changes: <span id="changes">0</span></div> <div>Letters: <span id="letterStats"></span></div> <label><input type="checkbox" id="limit"> Limit to available</label> <label><input type="checkbox" id="reuse"> Reuse replaced</label> <div id="storage"></div> <div>FPS: <input type="range" id="fps" min="1" max="60" value="10"></div> </div> </div> <div id="info">Hover a cell</div> </div> <script> const w = 30, h = 20; const cellSize = 20; let grid = Array(h).fill().map(() => Array(w).fill('.')); let nextGrid = Array(h).fill().map(() => Array(w).fill('.')); let changes = 0; let storage = { 'o': 10, '.': 20, ':': 5, '>': 3, '<': 3, '^': 3, 'v': 3, '=': 2, 'i': 2, 'f': 2, '9': 1, '*': 1, 'x': 5 }; let cursor = { x: 0, y: 0 }; let hoveredCell = null; let gameRunning = true; let fps = 10; let frameInterval; const letterInfo = { 'x': 'wall', 'o': 'item ball (movable, falls)', '.': 'item particle (movable)', ':': 'item particles (10% -> particle)', '>': 'right wall', '<': 'left wall', '^': 'up wall', 'v': 'down wall', '=': 'teleport (swap adjacent)', 'i': 'heat wall (adds heat)', 'f': 'cold wall (cools)', '9': 'sink (deletes near items)', '*': 'source (creates particles)' }; const gameDiv = document.getElementById('game'); gameDiv.style.gridTemplateColumns = `repeat(${w}, ${cellSize}px)`; gameDiv.style.gridTemplateRows = `repeat(${h}, ${cellSize}px)`; for (let y = 0; y < h; y++) { for (let x = 0; x < w; x++) { const cell = document.createElement('div'); cell.className = 'cell'; cell.dataset.x = x; cell.dataset.y = y; cell.textContent = grid[y][x]; cell.addEventListener('click', () => { cursor.x = x; cursor.y = y; updateCursor(); }); cell.addEventListener('mouseenter', () => { hoveredCell = { x, y }; updateInfo(); }); gameDiv.appendChild(cell); } } function updateCursor() { document.querySelectorAll('.cell').forEach(cell => { cell.style.background = ''; if (parseInt(cell.dataset.x) === cursor.x && parseInt(cell.dataset.y) === cursor.y) { cell.style.background = '#666'; } }); } function updateInfo() { const infoDiv = document.getElementById('info'); if (!hoveredCell) { infoDiv.textContent = 'Hover a cell'; return; } const { x, y } = hoveredCell; const ch = grid[y][x]; infoDiv.innerHTML = `Cell: [${x},${y}]<br>Content: '${ch}'<br>${letterInfo[ch] || 'unknown'}`; } function updateStats() { document.getElementById('changes').textContent = changes; let stats = ''; for (const [letter, count] of Object.entries(storage)) { stats += `${letter}:${count} `; } document.getElementById('letterStats').textContent = stats; const storageDiv = document.getElementById('storage'); storageDiv.innerHTML = ''; for (const [letter, count] of Object.entries(storage)) { const span = document.createElement('span'); span.textContent = `${letter}:${count} `; span.title = letterInfo[letter] || ''; span.style.cursor = 'help'; storageDiv.appendChild(span); } } document.addEventListener('keydown', e => { if (e.key.length === 1) { const ch = e.key; if (document.getElementById('limit').checked && !storage[ch]) return; const old = grid[cursor.y][cursor.x]; if (old !== ch) { grid[cursor.y][cursor.x] = ch; changes++; if (document.getElementById('reuse').checked && /[o.:><^v=if9*]/.test(old)) { storage[old] = (storage[old] || 0) + 1; } if (/[o.:><^v=if9*]/.test(ch)) { storage[ch] = (storage[ch] || 0) - 1; } updateStats(); render(); } } }); function render() { for (let y = 0; y < h; y++) { for (let x = 0; x < w; x++) { const cell = document.querySelector(`.cell[data-x="${x}"][data-y="${y}"]`); cell.textContent = grid[y][x]; let color = 'white'; if (grid[y][x] === 'i') color = '#ff5555'; else if (grid[y][x] === 'f') color = '#5555ff'; cell.style.color = color; } } } function simulate() { if (!gameRunning) return; // Clear nextGrid for (let y = 0; y < h; y++) { for (let x = 0; x < w; x++) { nextGrid[y][x] = grid[y][x]; } } // Handle movement propagation for 'o' and ':' const movers = []; for (let y = 0; y < h; y++) { for (let x = 0; x < w; x++) { const ch = grid[y][x]; if (ch === 'o' || ch === ':') { movers.push({ x, y, ch }); } } } // Process movers for (const m of movers) { let { x, y, ch } = m; let dir = null; // Check adjacent walls for direction if (x > 0 && grid[y][x-1] === '>') dir = [1, 0]; else if (x < w-1 && grid[y][x+1] === '<') dir = [-1, 0]; else if (y > 0 && grid[y-1][x] === 'v') dir = [0, 1]; else if (y < h-1 && grid[y+1][x] === '^') dir = [0, -1]; else if (y < h-1 && grid[y+1][x] === 'x' && ch === 'o') dir = [0, -1]; // gravity for balls if (dir) { const nx = x + dir[0]; const ny = y + dir[1]; if (nx >= 0 && nx < w && ny >= 0 && ny < h) { const target = grid[ny][nx]; if (target === '.' || target === ':') { nextGrid[y][x] = '.'; nextGrid[ny][nx] = ch; } } } } // Handle special mechanics for (let y = 0; y < h; y++) { for (let x = 0; x < w; x++) { const ch = grid[y][x]; if (ch === ':') { if (Math.random() < 0.1) { nextGrid[y][x] = '.'; } } else if (ch === '=') { if (x > 0 && x < w-1) { const left = grid[y][x-1]; const right = grid[y][x+1]; nextGrid[y][x-1] = right; nextGrid[y][x+1] = left; } } else if (ch === 'i' || ch === 'f') { const dy = [-1,0,1,0]; const dx = [0,1,0,-1]; for (let d = 0; d < 4; d++) { const ny = y + dy[d]; const nx = x + dx[d]; if (nx >= 0 && nx < w && ny >= 0 && ny < h) { const target = grid[ny][nx]; if (target === 'o') { // Heat/cold effect - simplified as immediate conversion if (ch === 'i') { nextGrid[ny][nx] = '.'; } } } } } else if (ch === '9') { const dy = [-1,-1,-1,0,0,1,1,1]; const dx = [-1,0,1,-1,1,-1,0,1]; for (let d = 0; d < 8; d++) { const ny = y + dy[d]; const nx = x + dx[d]; if (nx >= 0 && nx < w && ny >= 0 && ny < h) { const target = grid[ny][nx]; if (/[o.:]/.test(target)) { nextGrid[ny][nx] = '.'; } } } } else if (ch === '*') { const dy = [-1,-1,-1,0,0,1,1,1]; const dx = [-1,0,1,-1,1,-1,0,1]; const free = []; for (let d = 0; d < 8; d++) { const ny = y + dy[d]; const nx = x + dx[d]; if (nx >= 0 && nx < w && ny >= 0 && ny < h && grid[ny][nx] === '.') { free.push({x:nx, y:ny}); } } if (free.length > 0) { const choice = free[Math.floor(Math.random() * free.length)]; nextGrid[choice.y][choice.x] = '.'; } } } } // Swap buffers [grid, nextGrid] = [nextGrid, grid]; render(); } function startGame() { clearInterval(frameInterval); frameInterval = setInterval(simulate, 1000 / fps); } document.getElementById('fps').addEventListener('input', e => { fps = parseInt(e.target.value); startGame(); }); document.getElementById('limit').addEventListener('change', updateStats); document.getElementById('reuse').addEventListener('change', updateStats); updateCursor(); updateStats(); startGame(); </script> </body> </html>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.