import { grid, cols, rows } from './state.js'; import { move } from './actions.js'; export function updateDirt(x, y, cell) { const below = y + 1; if (below >= rows) return; const belowCell = grid[x][below]; if (!belowCell) { move(x, y, x, below); } else if (belowCell.type === 'water' || belowCell.type === 'acid') { // Fall through water or acid (slower) if (Math.random() < 0.2) { grid[x][below] = cell; grid[x][y] = belowCell; cell.updated = true; belowCell.updated = true; } } else { // Try sliding left or right const left = x > 0 && !grid[x - 1][below]; const right = x < cols - 1 && !grid[x + 1][below]; if (left && right) move(x, y, Math.random() < 0.5 ? x - 1 : x + 1, below); else if (left) move(x, y, x - 1, below); else if (right) move(x, y, x + 1, below); } }