deterministic-map
v1.0.4
Published
A deterministic map generator using cryptographic hashes for reproducible game maps
Maintainers
Readme
Deterministic Map Generator
https://cryptohunter.fun
A deterministic map generation system that creates game maps based on cryptographic hashes. This system uses a random hash to generate consistent, reproducible maps for games.
Features
- Deterministic Generation: Same input always produces the same output
- Cryptographic Entropy: Uses SHA-256 hashing for unpredictable but reproducible randomness
- Modular Design: Separate classes for dice, land generation, and player positioning
- Extensible: Easy to add new land types and generation rules
Project Structure
deterministic-map/
├── src/
│ ├── index.js # Main exports
│ ├── dice.js # DeterministicDice class
│ ├── gameLandGenerator.js # GameLandGenerator class
│ └── playerPositionGenerator.js # PlayerPositionGenerator class
├── example/
│ └── generateMap.js # Example usage script
├── random_sample.txt # Sample random hash
├── package.json # Project dependencies
└── README.md # This fileClasses
DeterministicDice
Generates deterministic random numbers based on a cryptographic hash.
- Constructor: Takes a random hash as entropy source
- roll(count): Generates random numbers using hex characters
- rehashEntropy(): Extends entropy by hashing when needed
GameLandGenerator
Generates game maps with different land types.
- generateLand(): Creates a grid of land tiles
- placeTreasure(): Places treasure locations (1 + map size / 12)
- saveMapToFile(): Saves map data to JSON file
- printMapSummary(): Displays land type statistics
PlayerPositionGenerator
Generates deterministic starting positions for players.
- generateStartingPosition(): Creates position for single player
- generateAllPlayerPositions(): Creates positions for multiple players
Usage
Basic Example
import { DeterministicDice, GameLandGenerator } from "./src/index.js";
// Create dice with random hash
const dice = new DeterministicDice("0x1234567890abcdef...");
// Generate 20x20 map
const generator = new GameLandGenerator(dice, 20);
generator.generateLand();
generator.placeTreasure();
generator.saveMapToFile("my_map.txt");Command Line Usage
# Generate map for game ID "sample"
node example/generateMap.js sample
# Or with explicit parameter
node example/generateMap.js --gameId=sampleThis requires a file named random_sample.txt containing the random hash.
Land Types
- Type 1: Common land (probability: 11/16)
- Type 2: Uncommon land (probability: 4/16)
- Type 3: Rare land (probability: 1/16)
- Type X: Treasure
Installation
npm installDependencies
- Node.js (ES modules support)
- Built-in
cryptomodule for hashing - Built-in
fsmodule for file operations
Testing
Use the provided random_sample.txt file to test the system:
node example/generateMap.js sampleThis will generate a map_sample.txt file with the deterministic map data.
