Skip to content

gomezAlvaro/sm-rando-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

44 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Map Randomizer - Java Proof of Concept

A Java implementation of core concepts from the Super Metroid Map Randomizer, demonstrating item randomization algorithms and game state management.

🎯 Project Overview

This is a learning project that ports core components of the Super Metroid Map Randomizer from Rust to Java. It demonstrates fundamental randomization concepts while providing a functional proof-of-concept.

What This Project Does

βœ… Core Data Models - Java representations of game entities (items, resources, inventory) βœ… Basic Inventory System - Item collection and resource management βœ… Simple Randomization Logic - Basic item placement algorithms βœ… Game State Management - Tracking player state and inventory βœ… Working Demonstration - A runnable example showing the concept βœ… JSON Data Loading - Load items, locations, and requirements from external JSON files

What This Project Does NOT Do (Yet)

❌ Full ROM patching system (partial - BPS/IPS implemented) ❌ Complete escape timing data integration (algorithm complete, needs game data) ❌ Production deployment configuration ❌ Multi-player/multi-world support

Recently Implemented (Phase 4)

βœ… Escape Timer System - Graph-based escape timer with Dijkstra's algorithm βœ… Run Speed Calculations - Accurate runway distance and shortcharge mechanics βœ… Difficulty Config System - Tech abilities and preset configurations βœ… Advanced Quality Settings - Escape enemies cleared, Mother Brain fight options βœ… Comprehensive Testing - 329 tests including 22 new Phase 4 tests

πŸ“ Project Structure

map-randomizer-poc/
β”œβ”€β”€ pom.xml                                    # Maven configuration
β”œβ”€β”€ README.md                                  # This file
└── src/
    β”œβ”€β”€ main/java/com/maprando/
    β”‚   β”œβ”€β”€ model/                            # Core data structures
    β”‚   β”‚   β”œβ”€β”€ Item.java                     # 24 major items enum
    β”‚   β”‚   β”œβ”€β”€ ResourceType.java             # Resource types (energy, missiles, etc.)
    β”‚   β”‚   β”œβ”€β”€ ResourceLevel.java            # Resource consumption tracking
    β”‚   β”‚   β”œβ”€β”€ Inventory.java                # Player inventory management
    β”‚   β”‚   └── GameState.java                # Game state representation
    β”‚   β”œβ”€β”€ logic/                            # Game logic and rules
    β”‚   β”‚   β”œβ”€β”€ ItemCollector.java            # Item pickup logic
    β”‚   β”‚   β”œβ”€β”€ ResourceManager.java          # Resource availability checks
    β”‚   β”‚   β”œβ”€β”€ RequirementChecker.java       # Requirement satisfaction logic
    β”‚   β”‚   └── DamageCalculator.java         # Simple damage calculations
    β”‚   β”œβ”€β”€ randomize/                        # Randomization algorithms
    β”‚   β”‚   β”œβ”€β”€ Location.java                 # Item placement locations
    β”‚   β”‚   β”œβ”€β”€ ItemPool.java                 # Available items for placement
    β”‚   β”‚   β”œβ”€β”€ BasicRandomizer.java          # Simple randomization algorithm
    β”‚   β”‚   └── RandomizationResult.java      # Output of randomization
    β”‚   └── demo/                             # Demonstration programs
    β”‚       β”œβ”€β”€ SimpleDemo.java               # Main demonstration
    β”‚       └── PrintableSpoiler.java         # Formatted spoiler output
    └── test/java/com/maprando/
        β”œβ”€β”€ model/
        β”œβ”€β”€ logic/
        └── randomize/

πŸš€ Getting Started

Prerequisites

  • Java 21 or higher (for modern language features: records, pattern matching)
  • Maven 3.8+ (for dependency management)

Building the Project

# Clone or navigate to the project directory
cd sm-java

# Compile the project
mvn clean compile

# Run tests (when available)
mvn test

# Run the demonstration
mvn exec:java -Dexec.mainClass="com.maprando.demo.SimpleDemo"

Running the Demo

The demonstration program shows:

  1. Creating a game state with starting items
  2. Demonstrating item collection
  3. Demonstrating resource management
  4. Creating an item pool
  5. Defining item locations
  6. Running randomization
  7. Printing a spoiler log
  8. Verifying completion
mvn exec:java -Dexec.mainClass="com.maprando.demo.SimpleDemo"

πŸ“š Key Concepts

1. Item System

The Item enum defines 24 major items including:

  • Beams: Charge, Ice, Wave, Spazer, Plasma
  • Morph Ball: Morph Ball, Bomb, Spring Ball, Power Bomb
  • Movement: Hi-Jump Boots, Speed Booster, Space Jump, Screw Attack
  • Suits: Varia Suit, Gravity Suit
  • Keys: Area keys for boss access
  • Tanks: Energy, Missile, Super Missile, Power Bomb
// Check if player can morph
boolean canMorph = RequirementChecker.canMorph(gameState);

// Collect an item
ItemCollector.collectItem(gameState, Item.ICE_BEAM);

2. Resource Management

Resources track both capacity and consumption:

  • Energy: Health points (100-299)
  • Missiles: Missile ammo (0-250)
  • Super Missiles: Super missile ammo (0-50)
  • Power Bombs: Power bomb ammo (0-50)
// Check resource availability
boolean canShoot = ResourceManager.hasResource(state, ResourceType.MISSILE, 5);

// Consume resources
ResourceManager.consumeResource(state, ResourceType.MISSILE, 5);

3. Game State

GameState tracks everything about the player:

  • Inventory (collected items)
  • Resource capacities and consumption
  • Current position
  • Health
// Create a standard starting state
GameState state = GameState.standardStart();

// Clone state for traversal simulations
GameState clonedState = state.clone();

4. Randomization

The basic randomizer uses a simple progression algorithm:

  1. Separate locations into early (no requirements) and late (has requirements)
  2. Place progression items in early locations first
  3. Place remaining progression items in late locations
  4. Fill remaining locations with filler items (tanks)
// Create a randomizer with a seed
BasicRandomizer randomizer = new BasicRandomizer("my-seed-123");

// Add locations
randomizer.addLocation(location);

// Set item pool
randomizer.setItemPool(ItemPool.createStandardPool());

// Run randomization
RandomizationResult result = randomizer.randomize();

// Print spoiler log
System.out.println(result.generateSpoilerLog());

πŸ—οΈ Architecture Decisions

Design Patterns

  • Strategy Pattern: For different randomization algorithms (extensible)
  • Builder Pattern: For complex object construction (Location, RandomizationResult)
  • Immutable Objects: For game state (easier reasoning about state)
  • Record Classes: For immutable data structures (ResourceLevel)

Performance Considerations

  • EnumSet: For efficient item collection storage
  • Bitwise Operations: For capacity tracking where applicable
  • Immutable State: Enables safe cloning for traversal
  • Lazy Evaluation: Expensive computations only when needed

πŸ“– Learning Outcomes

This project demonstrates:

  1. Rust-to-Java Translation: How to think about ownership and borrowing in Java terms
  2. Game State Management: Complex state tracking and updates
  3. Randomization Algorithms: Progressive item placement and difficulty balancing
  4. Functional Programming: Using Java's functional features for data transformations
  5. Performance Optimization: When and how to optimize Java code for game logic

πŸ”§ Extending the Project

Future Expansion Ideas

  1. JSON Data Loading - Load real game data from external files
  2. Graph Traversal - Implement reachability analysis for proper verification
  3. Difficulty Tiers - Add difficulty levels for randomization
  4. Advanced Algorithms - Implement more sophisticated randomization strategies
  5. ROM Patching - Add ability to modify actual ROM files
  6. Web Interface - Create a web UI for seed generation

Adding a New Item

// In Item.java
NEW_ITEM("New Item", "Description"),

// Add helper methods if needed
public boolean isNewItem() {
    return this == NEW_ITEM;
}

Adding a New Randomization Algorithm

public class AdvancedRandomizer extends BasicRandomizer {
    @Override
    public RandomizationResult randomize() {
        // Implement advanced logic
    }
}

πŸ“Š Code Statistics

  • Total Files: 27 Java classes + 4 JSON data files
  • Lines of Code: ~3,500 (excluding JSON and tests)
  • Packages: 6 (model, logic, randomize, demo, data, test)
  • Dependencies: 4 (Apache Commons Lang, Guava, JUnit 5, Jackson)

πŸ§ͺ Testing

The project includes test directories for unit tests. To run tests:

mvn test

Test structure:

src/test/java/com/maprando/
β”œβ”€β”€ model/       # Test data models
β”œβ”€β”€ logic/       # Test game logic
└── randomize/   # Test randomization algorithms

πŸ“ Example Output

Spoiler Log

=== MAP RANDOMIZER SPOILER LOG ===
Seed: demo-seed-123
Timestamp: 2026-03-17T12:34:56.789
Algorithm: Basic Progression Randomizer
Status: SUCCESS
Items Placed: 10

[Brinstar]
  Morph Ball Room (Brinstar) -> Morph Ball
  Charge Beam Room (Brinstar) -> Energy Tank

[Norfair]
  Ice Beam Room (Norfair) -> Ice Beam
  Speed Booster Room (Norfair) -> Varia Suit
...

πŸ“Š JSON Data Loading System

The project now supports loading game data from external JSON files, making it easy to configure without recompiling.

Running the JSON Demo

mvn exec:java -Dexec.mainClass="com.maprando.demo.JsonDataDemo"

JSON Data Files

Located in src/main/resources/data/:

items.json - 27 items with properties:

  • Categories (beam, movement, suit, key, tank, etc.)
  • Progression flags
  • Damage multipliers and bonuses
  • Requirements and enables

locations.json - 15 locations:

  • Area and region information
  • Accessibility requirements
  • Early game flags
  • Boss location flags

requirements.json - Requirement definitions:

  • Tech requirements (can_morph, can_survive_heat, etc.)
  • Item dependencies
  • Logical conditions

difficulties.json - 5 difficulty presets:

  • Casual, Normal, Hard, Expert, Nightmare
  • Enemy damage/health multipliers
  • Resource multipliers
  • Starting items

Customizing Game Data

Simply edit the JSON files and restart the application:

{
  "id": "NEW_ITEM",
  "displayName": "New Item",
  "category": "utility",
  "isProgression": true,
  "description": "Custom item for testing"
}

Data Loading API

// Load all JSON data
DataLoader dataLoader = new DataLoader();
dataLoader.loadAllData();

// Access item definitions
ItemData.ItemDefinition itemDef = dataLoader.getItemDefinition("CHARGE_BEAM");

// Create game objects from JSON
ItemPool pool = createItemPoolFromJson(dataLoader);
List<Location> locations = createLocationsFromJson(dataLoader);

🀝 Contributing

This is a learning project. Suggestions and improvements are welcome!

Areas for Contribution

  1. Add unit tests for existing classes
  2. Implement graph traversal for proper reachability
  3. Add more sophisticated randomization algorithms
  4. Create additional demo programs
  5. Improve documentation and examples

πŸ“„ License

This is a proof-of-concept for educational purposes. The original MapRandomizer project has its own license.

πŸ™ Acknowledgments

  • Original MapRandomizer project (Rust implementation)
  • Super Metroid - The game this randomizer is based on
  • Java community for excellent libraries and tools

πŸ“ž Support

For questions or issues:

  1. Check the code comments and documentation
  2. Review the demonstration program
  3. Examine the test cases (when available)

Status: Proof of Concept βœ… Last Updated: March 2026 Java Version: 21

About

SM Randomizer vibe-ported to java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors