A Java application that simulates loading cargo into a 53-foot dry van trailer. The program accepts a sequence of shapes and column positions, simulates gravity and collision detection, and calculates the maximum stack height.
- Java 21 (or higher)
- No manual Maven installation required (Maven Wrapper included)
Use the included Maven Wrapper to build the project and run tests:
./mvnw clean package
The application reads from Standard Input (stdin). You can run it via the command line by piping input or running the jar directly.
Option 1: Using the executable JAR (Recommended) After building the project, the JAR file will be located in the target directory.
echo "3O,9I,0J" | java -jar target/DryVanTetris-1.0-SNAPSHOT.jar
Option 2: Running with Maven You can also run the application directly using the Maven Wrapper without packaging it first.
echo "3O,9I,0J" | ./mvnw -q exec:java -Dexec.mainClass="com.justin.Main"
The input must be a comma-separated string of cargo records in the format [Column][Shape].
- Column: 0 through 9 (Represents the leftmost column of the shape).
- Shape: O, I, S, Z, L, J, T (Standard Tetromino shapes).
Example Input:
7S,7I,5Z
- Coordinates: The grid uses a standard Cartesian system where the "floor" is y=0 and the top is y=52.
- Collision Logic: Shapes fall until any part of them collides with the floor or another locked piece.
- Rigid Bodies: The shapes are rigid. If one part of a shape hits a tower while another part hangs over empty space, the entire shape stops and locks in place (it does not break or slide).
- Output: The program outputs a single integer representing the highest occupied 0-indexed y-coordinate (or 0 if empty).