Skip to main content

phase1_demo/
phase1_demo.rs

1use terrain_forge::{algorithms, semantic::*, Grid, Rng, SemanticExtractor};
2
3fn main() {
4    println!("=== TerrainForge v0.4.0 Phase 1 Demo ===\n");
5
6    // Demo 1: Hierarchical Marker Types
7    demo_hierarchical_markers();
8
9    // Demo 2: Generate with Requirements
10    demo_generate_with_requirements();
11
12    // Demo 3: Vertical Connectivity
13    demo_vertical_connectivity();
14}
15
16fn demo_hierarchical_markers() {
17    println!("🎯 Demo 1: Hierarchical Marker Types");
18
19    let mut grid = Grid::new(40, 30);
20    algorithms::get("bsp").unwrap().generate(&mut grid, 12345);
21
22    let extractor = SemanticExtractor::for_rooms();
23    let mut rng = Rng::new(12345);
24    let mut semantic = extractor.extract(&grid, &mut rng);
25
26    // Add hierarchical markers manually for demo
27    if let Some(region) = semantic.regions.first() {
28        let (x, y) = region.cells[0];
29
30        // Quest markers
31        semantic.markers.push(Marker::new(
32            x,
33            y,
34            MarkerType::QuestObjective { priority: 1 },
35        ));
36        semantic
37            .markers
38            .push(Marker::new(x + 2, y, MarkerType::QuestStart));
39
40        // Loot markers
41        semantic
42            .markers
43            .push(Marker::new(x, y + 2, MarkerType::LootTier { tier: 3 }));
44        semantic
45            .markers
46            .push(Marker::new(x + 1, y + 2, MarkerType::Treasure));
47
48        // Encounter zones
49        semantic.markers.push(Marker::new(
50            x + 3,
51            y + 1,
52            MarkerType::EncounterZone { difficulty: 5 },
53        ));
54        semantic
55            .markers
56            .push(Marker::new(x + 4, y + 1, MarkerType::BossRoom));
57    }
58
59    // Show marker categories
60    let mut categories = std::collections::HashMap::new();
61    for marker in &semantic.markers {
62        *categories.entry(marker.marker_type.category()).or_insert(0) += 1;
63    }
64
65    for (category, count) in categories {
66        println!("  {} markers: {}", category, count);
67    }
68
69    println!("  Sample markers:");
70    for marker in semantic.markers.iter().take(3) {
71        println!("    {} at ({}, {})", marker.tag(), marker.x, marker.y);
72    }
73    println!();
74}
75
76fn demo_generate_with_requirements() {
77    println!("📋 Demo 2: Generate with Requirements");
78
79    let mut requirements = SemanticRequirements::basic_dungeon();
80    requirements.min_regions.insert("room".to_string(), 4);
81    requirements
82        .required_markers
83        .insert(MarkerType::LootTier { tier: 1 }, 2);
84
85    match terrain_forge::generate_with_requirements("bsp", 60, 40, requirements, Some(5), 54321) {
86        Ok((grid, semantic)) => {
87            println!("  ✅ Generated valid dungeon!");
88            println!("  Regions: {}", semantic.regions.len());
89            println!("  Markers: {}", semantic.markers.len());
90            println!("  Floor tiles: {}", grid.count(|t| t.is_floor()));
91        }
92        Err(msg) => println!("  ❌ Failed: {}", msg),
93    }
94    println!();
95}
96
97fn demo_vertical_connectivity() {
98    println!("🏗️ Demo 3: Vertical Connectivity");
99
100    // Create two simple floor grids
101    let mut floor1 = Grid::new(20, 20);
102    let mut floor2 = Grid::new(20, 20);
103
104    // Add some floor areas
105    for y in 5..15 {
106        for x in 5..15 {
107            floor1.set(x, y, terrain_forge::Tile::Floor);
108            floor2.set(x, y, terrain_forge::Tile::Floor);
109        }
110    }
111
112    let floors = vec![floor1, floor2];
113    let mut connectivity = VerticalConnectivity::new();
114
115    connectivity.analyze_stair_candidates(&floors, 2);
116    connectivity.place_stairs(3);
117
118    println!(
119        "  Stair candidates found: {}",
120        connectivity.stair_candidates.len()
121    );
122    println!("  Stairs placed: {}", connectivity.stairs.len());
123
124    if let Some((x, y, from, to)) = connectivity.stairs.first() {
125        println!(
126            "  Sample stair: ({}, {}) connecting floor {} to {}",
127            x, y, from, to
128        );
129    }
130    println!();
131}