1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::world::place::PlaceData;
use crate::world::{word, Demographics};
use rand::prelude::*;

pub fn generate(place: &mut PlaceData, rng: &mut impl Rng, _demographics: &Demographics) {
    place.name.replace_with(|_| name(rng));
}

fn name(rng: &mut impl Rng) -> String {
    match rng.gen_range(0..7) {
        0..=2 => format!("The {}", thing(rng)),
        3..=5 => format!("{} {}", thing(rng), theater_synonym(rng)),
        6 => format!(
            "{} {} {}",
            word::adjective(rng),
            thing(rng),
            theater_synonym(rng)
        ),
        _ => unreachable!(),
    }
}

fn thing(rng: &mut impl Rng) -> &'static str {
    match rng.gen_range(0..6) {
        0 => word::animal(rng),
        1..=2 => word::symbol(rng),
        3..=4 => word::gem(rng),
        5 => word::person(rng),
        _ => unreachable!(),
    }
}

fn theater_synonym(rng: &mut impl Rng) -> &'static str {
    #[rustfmt::skip]
    const THEATER_SYNONYMS: &[&str] = &[
        "Theater", "Opera House", "Ampitheater", "Hall", "Playhouse",
    ];
    THEATER_SYNONYMS[rng.gen_range(0..THEATER_SYNONYMS.len())]
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn name_test() {
        let mut rng = SmallRng::seed_from_u64(0);

        assert_eq!(
            [
                "Lance Playhouse",
                "Lucky Helmet Playhouse",
                "The Mermaid",
                "The Opal",
                "Sun Playhouse",
                "Bronze Steeple Theater",
                "The Sibling",
                "Anchor Hall",
                "Book Ampitheater",
                "Foil Ampitheater",
                "Deer Ampitheater",
                "Amber Theater",
                "The Otter",
                "Ancestor Hall",
                "Diamond Opera House",
                "Green Sapphire Playhouse",
                "The Rook",
                "Purple Opal Theater",
                "Feather Playhouse",
                "Phalactary Ampitheater"
            ]
            .iter()
            .map(|s| s.to_string())
            .collect::<Vec<_>>(),
            (0..20).map(|_| name(&mut rng)).collect::<Vec<String>>(),
        );
    }
}