rust/landgen/src/wavefront_collapse/wavefront_collapse.rs
author unC0Rr
Fri, 03 Feb 2023 14:44:33 +0100
branchtransitional_engine
changeset 15916 e82de0410da5
parent 15915 8f093b1b18bc
child 15917 60b5639cc3a5
permissions -rw-r--r--
Rework how rules are defined, add transformations for tiles
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
     1
use integral_geometry::Size;
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
     2
use std::collections::{HashMap, HashSet};
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
     3
use vec2d::Vec2D;
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
     4
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
     5
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
     6
pub enum Tile {
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
     7
    Empty,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
     8
    Outside,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
     9
    Numbered(u32),
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    10
}
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    11
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    12
impl Tile {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    13
    fn is(&self, i: u32) -> bool {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    14
        *self == Tile::Numbered(i)
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    15
    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    16
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    17
    fn is_empty(&self) -> bool {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    18
        match self {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    19
            Tile::Empty => true,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    20
            Tile::Outside => true,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    21
            _ => false,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    22
        }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    23
    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    24
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    25
    fn is_empty_or(&self, i: u32) -> bool {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    26
        match self {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    27
            Tile::Numbered(n) => *n == i,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    28
            Tile::Empty => true,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    29
            _ => false,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    30
        }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    31
    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    32
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    33
    fn is_void_or(&self, i: u32) -> bool {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    34
        match self {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    35
            Tile::Numbered(n) => *n == i,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    36
            _ => true,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    37
        }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    38
    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    39
}
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    40
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    41
impl Default for Tile {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    42
    fn default() -> Self {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    43
        Tile::Outside
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    44
    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    45
}
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    46
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    47
pub struct CollapseRule {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    48
    tile: Tile,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    49
    right: HashSet<Tile>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    50
    bottom: HashSet<Tile>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    51
    left: HashSet<Tile>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    52
    top: HashSet<Tile>,
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    53
}
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    54
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    55
pub struct WavefrontCollapse {
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    56
    rules: Vec<CollapseRule>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    57
    grid: Vec2D<Tile>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    58
}
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    59
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    60
impl Default for WavefrontCollapse {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    61
    fn default() -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    62
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    63
            rules: Vec::new(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    64
            grid: Vec2D::new(&Size::new(1, 1), Tile::Empty),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    65
        }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    66
    }
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    67
}
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    68
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    69
impl WavefrontCollapse {
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
    70
    pub fn generate_map<I: Iterator<Item = u32>, F: FnOnce(&mut Vec2D<Tile>)>(
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    71
        &mut self,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    72
        map_size: &Size,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    73
        seed_fn: F,
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    74
        random_numbers: &mut I,
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    75
    ) {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    76
        self.grid = Vec2D::new(&map_size, Tile::Empty);
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    77
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    78
        seed_fn(&mut self.grid);
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    79
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    80
        while self.collapse_step(random_numbers) {}
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    81
    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    82
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    83
    fn add_rule(&mut self, rule: CollapseRule) {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    84
        self.rules.push(rule);
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    85
    }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    86
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    87
    fn get_tile(&self, y: usize, x: usize) -> Tile {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    88
        self.grid.get(y, x).map(|p| *p).unwrap_or_default()
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    89
    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    90
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    91
    fn collapse_step<I: Iterator<Item = u32>>(&mut self, random_numbers: &mut I) -> bool {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    92
        let mut tiles_to_collapse = (usize::max_value(), Vec::new());
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    93
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    94
        // Iterate through the tiles in the land
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    95
        for x in 0..self.grid.width() {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    96
            for y in 0..self.grid.height() {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    97
                let current_tile = self.get_tile(y, x);
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
    98
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
    99
                if let Tile::Empty = current_tile {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   100
                    // calc entropy
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   101
                    let right_tile = self.get_tile(y, x + 1);
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   102
                    let bottom_tile = self.get_tile(y + 1, x);
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   103
                    let left_tile = self.get_tile(y, x.wrapping_sub(1));
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   104
                    let top_tile = self.get_tile(y.wrapping_sub(1), x);
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   105
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   106
                    let possibilities: Vec<Tile> = self
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   107
                        .rules
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   108
                        .iter()
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   109
                        .filter_map(|rule| {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   110
                            if rule.right.contains(&right_tile)
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   111
                                && rule.bottom.contains(&bottom_tile)
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   112
                                && rule.left.contains(&left_tile)
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   113
                                && rule.top.contains(&top_tile)
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   114
                            {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   115
                                Some(rule.tile)
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   116
                            } else {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   117
                                None
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   118
                            }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   119
                        })
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   120
                        .collect();
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   121
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   122
                    let entropy = possibilities.len();
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   123
                    if entropy > 0 && entropy <= tiles_to_collapse.0 {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   124
                        let entry = (
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   125
                            y,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   126
                            x,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   127
                            possibilities
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   128
                                [random_numbers.next().unwrap_or_default() as usize % entropy],
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   129
                        );
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   130
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   131
                        if entropy < tiles_to_collapse.0 {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   132
                            tiles_to_collapse = (entropy, vec![entry])
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   133
                        } else {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   134
                            tiles_to_collapse.1.push(entry)
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   135
                        }
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   136
                    } else {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   137
                        todo!("no collapse possible")
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   138
                    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   139
                }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   140
            }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   141
        }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   142
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   143
        let tiles_to_collapse = tiles_to_collapse.1;
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   144
        let possibilities_number = tiles_to_collapse.len();
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   145
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   146
        if possibilities_number > 0 {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   147
            let (y, x, tile) = tiles_to_collapse
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   148
                [random_numbers.next().unwrap_or_default() as usize % possibilities_number];
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   149
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   150
            *self
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   151
                .grid
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   152
                .get_mut(y, x)
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   153
                .expect("correct iteration over grid") = tile;
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   154
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   155
            true
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   156
        } else {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   157
            false
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   158
        }
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   159
    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   160
}
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   161
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   162
#[cfg(test)]
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   163
mod tests {
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   164
    use super::{Tile, WavefrontCollapse};
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   165
    use integral_geometry::Size;
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   166
    use vec2d::Vec2D;
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   167
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   168
    #[test]
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   169
    fn test_wavefront_collapse() {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   170
        let size = Size::new(4, 4);
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   171
        let mut rnd = [0u32; 64].into_iter();
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   172
        let mut wfc = WavefrontCollapse::default();
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   173
15913
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents: 15912
diff changeset
   174
        let empty_land = Vec2D::new(&size, Tile::Empty);
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   175
15916
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15915
diff changeset
   176
        assert_eq!(empty_land.as_slice(), wfc.grid.as_slice());
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   177
    }
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents:
diff changeset
   178
}