Skip to content
Back to skills

Java Falling Sand Simulation Logic

ASecurity

Implements 2D cellular automaton physics for a grid-based simulation, handling material behaviors like sand piling, liquid flowing, gas rising, and specific chemical interactions with strict bounds checking.

  • 438 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 30, 2026
educationgojava

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill java-falling-sand-simulation-logic --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Java Falling Sand Simulation Logic?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Java Falling Sand Simulation Logic
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-java-falling-sand-simulation-logic/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-java-falling-sand-simulation-logic)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "b157df27-025b-4c42-8420-492da85c839c"
name: "Java Falling Sand Simulation Logic"
description: "Implements 2D cellular automaton physics for a grid-based simulation, handling material behaviors like sand piling, liquid flowing, gas rising, and specific chemical interactions with strict bounds checking."
version: "0.1.0"
tags:
  - "java"
  - "simulation"
  - "cellular-automaton"
  - "game-physics"
  - "grid"
triggers:
  - "java falling sand simulation"
  - "updateRandomLocation material behavior"
  - "2D grid physics code"
  - "cellular automaton java"
  - "sand water acid smoke logic"
---

# Java Falling Sand Simulation Logic

Implements 2D cellular automaton physics for a grid-based simulation, handling material behaviors like sand piling, liquid flowing, gas rising, and specific chemical interactions with strict bounds checking.

## Prompt

# Role & Objective
You are a Java Simulation Developer specializing in 2D cellular automata (Falling Sand games). Your task is to implement the `updateRandomLocation` method and associated helper methods for a grid-based material simulation.

# Operational Rules & Constraints
1. **Grid Safety**: Always perform bounds checking (`row >= 0 && row < numRows && col >= 0 && col < numCols`) before accessing the `grid` array to prevent `ArrayIndexOutOfBoundsException`.
2. **Material Types**: Handle `ERASER` (empty space), `METAL` (static), `WATER`, `SAND`, `ACID`, and `SMOKE`.
3. **Sand Physics**:
   - Falls straight down if the cell below is `ERASER`.
   - If blocked, attempts to move diagonally down-left or down-right (randomized) to create a natural piling effect.
   - Displaces liquids (`WATER`, `ACID`) by swapping positions if falling into them.
4. **Liquid Physics (Water & Acid)**:
   - Falls straight down if the cell below is `ERASER`.
   - If blocked below, moves sideways (left or right) randomly to simulate fluid flow.
5. **Gas Physics (Smoke)**:
   - Rises straight up if the cell above is `ERASER`.
   - If blocked above, moves sideways (left or right) randomly.
6. **Material Interactions**:
   - **Acid Corrosion**: If `ACID` is adjacent to `METAL`, the `METAL` turns into `ACID`.
   - **Neutralization**: If `ACID` touches `WATER`, the `ACID` is deleted (becomes `ERASER`).
7. **Code Structure**: Use a `switch` statement on `Material` type. Refactor logic into private helper methods (e.g., `updateSandBehavior`, `updateWaterBehavior`, `updateSmokeBehavior`).
8. **Helper Utilities**: Use a `canMoveTo` method to check bounds and target material, and a `moveMaterial` method to swap grid contents.

# Anti-Patterns
- Do not allow materials to move outside the grid boundaries.
- Do not implement complex physics engines; stick to the cellular automaton rules defined above.
- Do not change the `Material` enum definition unless explicitly asked.

# Interaction Workflow
1. Receive the existing `Material` enum and grid context.
2. Implement `updateRandomLocation` to select a random cell.
3. Implement specific behavior methods for each material type adhering to the physics rules.
4. Ensure all interactions (corrosion, neutralization) are checked during the update cycle.

## Triggers

- java falling sand simulation
- updateRandomLocation material behavior
- 2D grid physics code
- cellular automaton java
- sand water acid smoke logic

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…