City Address Builder
May 2024
A Rust-based city address generator. that creates horizontal and vertical streets, placing mailboxes along all street edges to generate structured addresses. The system efficiently calculates and reuses address numbers, producing thousands of unique locations. Street names are generated based on real names from Olympia, Washington.
Project Overview
A city-building simulation written in Rust, focused on the procedural generation of streets and mapping addresses. Inspired by real-world urban layouts—such as Olympia, WA—this lightweight terminal tool models city grids, assigns addresses to intersections, and visualizes road infrastructure via a grid-based ASCII map.
Rust-City-Builder is a command-line simulation that mimics the layout of a simple urban grid by randomly generating North-South and East-West roads. It assigns address names based on pre-defined sources (like Olympia street names) and maps them to a 2D grid, rendering it with basic ASCII visualization. Designed for experimenting with procedural content generation in Rust.
This project is a city address builder written in Rust that programmatically generates streets and avenues, placing mailboxes along all edges of the roads to create structured addresses. It ensures that every street segment has a properly numbered address, not just at intersections but along the entire length of each road. The generator estimates the number of possible addresses based on the city size, accounting for overlapping streets, double-wide roads, and address reuse when appropriate. A hashmap stores generated addresses, optimizing for efficient allocation while maintaining realistic numbering.
- The city is modeled as a 2D array: [['.'; BOUND]; BOUND]
- Roads (#) are laid in the grid at randomly spaced intervals
- Addresses/Mailboxes (o) are marked next to roads
- gen_random_roads() creates vertical and horizontal roads at randomized intervals
- Road direction: RoadDirection::NorthSouth or RoadDirection::EastWest
- AddressesMap (HashMap<(usize, usize), String>) stores generated address labels per coordinate
- Olympia street names are assigned from street-names.txt
- city_drawer() maps all roads to the grid
- Connected intersections are marked
- Results are printed as ASCII art in terminal
In-Memory Grid
Road Generator
Address Mapping
City Drawer
Project Features
- 🛣️ Randomly generates vertical and horizontal roads
- 🗺️ Displays a grid-based map of the city with roads (#), addresses/mailboxes (o), and empty land (.)
- 🏙️ Assigns street names and address strings to map coordinates
- 🔁 Modular architecture for city drawing, address management, and name reading
- 📦 Olympia-specific address data sourced from real geographic datasets
Project User Workflow
- Run the program with cargo run
- Watch as streets are generated and visualized in the terminal
- View a sample of assigned addresses printed with coordinate keys
- Extend or modify the city builder using alternate name sets or additional logic
Technologies Used
- 🦀 Rust programming language
- 📦 Cargo build system and package manager for Rust
- 📚 std::collections::HashMap for efficient address map storage
- 🎲 rand crate used for Random number generation for procedural layouts
- 📄 File I/O to parse real-world street names from text files
Project Images
Hello, city!
Added Road { coord: 6, direction: NorthSouth }
Added Road { coord: 13, direction: NorthSouth }
...
The number of generated addresses is 137
The address at coordinates (6, 8) is Martin Way E & Eastside St SE
The address at coordinates (13, 12) is Pacific Ave SE & Plum St SE
Grid Output:
.....o#o..........................................
.....o#o..........................................
.....o#o..........................................
.....o#o..........................................
.....o#o..........................................
oooooo#ooooooooooooooooooooooooooooooooooooooooooo
##################################################
oooooo#ooooooooooooooooooooooooooooooooooooooooooo
.....o#o..........................................