fn grow_rooms(&mut self, seeds: Vec<Position>, probability: f64, iterations: i32) -> Vec<Room> {
        let (w, h) = (self.map.width, self.map.height);

        let mut rng = RandomNumberGenerator::new();
        let mut rooms = Vec::new();

        for position in seeds {
            rooms.push(Room {
                x1: position.x,
                y1: position.y,
                x2: position.x,
                y2: position.y,
            })
        }

        for _ in 0..iterations {
            for i in 0..rooms.len() {
                // TODO: find a way of collapsing this, can't access slots by name in structs
                if rng.range(0.0, 1.0) < probability {
                    rooms[i].x1 -= 1;

                    if !rooms[i].in_bounds(w, h) {
                        rooms[i].x1 += 1;
                        continue;
                    }
                    let mut bad = false;
                    for j in 0..rooms.len() {
                        if i != j && rooms[i].overlap(&rooms[j]) {
                            bad = true;
                            break;
                        }
                    }

                    if bad {
                        rooms[i].x1 += 1;
                    }
                }

                if rng.range(0.0, 1.0) < probability {
                    rooms[i].y1 -= 1;

                    if !rooms[i].in_bounds(w, h) {
                        rooms[i].y1 += 1;
                        continue;
                    }
                    let mut bad = false;
                    for j in 0..rooms.len() {
                        if i != j && rooms[i].overlap(&rooms[j]) {
                            bad = true;
                            break;
                        }
                    }

                    if bad {
                        rooms[i].y1 += 1;
                    }
                }

                if rng.range(0.0, 1.0) < probability {
                    rooms[i].x2 += 1;

                    if !rooms[i].in_bounds(w, h) {
                        rooms[i].x2 -= 1;
                        continue;
                    }
                    let mut bad = false;
                    for j in 0..rooms.len() {
                        if i != j && rooms[i].overlap(&rooms[j]) {
                            bad = true;
                            break;
                        }
                    }

                    if bad {
                        rooms[i].x2 -= 1;
                    }
                }

                if rng.range(0.0, 1.0) < probability {
                    rooms[i].y2 += 1;

                    if !rooms[i].in_bounds(w, h) {
                        rooms[i].y2 -= 1;
                        continue;
                    }
                    let mut bad = false;
                    for j in 0..rooms.len() {
                        if i != j && rooms[i].overlap(&rooms[j]) {
                            bad = true;
                            break;
                        }
                    }

                    if bad {
                        rooms[i].y2 -= 1;
                    }
                }
            }
        }

        rooms
    }
/// Given a list of positions in the map, grow the rooms outwards
Given a list of positions in the map, grow the rooms outwards
Given a list of positions in the map grow the rooms outwards
fn grow_rooms(&mut self, seeds: Vec<Position>, probability: f64, iterations: i32) -> Vec<Room> {
        let (w, h) = (self.map.width, self.map.height);
        let mut rng = RandomNumberGenerator::new();
        let mut rooms = Vec::new();
        for position in seeds {
            rooms.push(Room {
                x1: position.x,
                y1: position.y,
                x2: position.x,
                y2: position.y,
            })
        }
        for _ in 0..iterations {
            for i in 0..rooms.len() {
                // TODO: find a way of collapsing this, can't access slots by name in structs
                if rng.range(0.0, 1.0) < probability {
                    rooms[i].x1 -= 1;
                    if !rooms[i].in_bounds(w, h) {
                        rooms[i].x1 += 1;
                        continue;
                    }
                    let mut bad = false;
                    for j in 0..rooms.len() {
                        if i != j && rooms[i].overlap(&rooms[j]) {
                            bad = true;
                            break;
                        }
                    }
                    if bad {
                        rooms[i].x1 += 1;
                    }
                }
                if rng.range(0.0, 1.0) < probability {
                    rooms[i].y1 -= 1;
                    if !rooms[i].in_bounds(w, h) {
                        rooms[i].y1 += 1;
                        continue;
                    }
                    let mut bad = false;
                    for j in 0..rooms.len() {
                        if i != j && rooms[i].overlap(&rooms[j]) {
                            bad = true;
                            break;
                        }
                    }
                    if bad {
                        rooms[i].y1 += 1;
                    }
                }
                if rng.range(0.0, 1.0) < probability {
                    rooms[i].x2 += 1;
                    if !rooms[i].in_bounds(w, h) {
                        rooms[i].x2 -= 1;
                        continue;
                    }
                    let mut bad = false;
                    for j in 0..rooms.len() {
                        if i != j && rooms[i].overlap(&rooms[j]) {
                            bad = true;
                            break;
                        }
                    }
                    if bad {
                        rooms[i].x2 -= 1;
                    }
                }
                if rng.range(0.0, 1.0) < probability {
                    rooms[i].y2 += 1;
                    if !rooms[i].in_bounds(w, h) {
                        rooms[i].y2 -= 1;
                        continue;
                    }
                    let mut bad = false;
                    for j in 0..rooms.len() {
                        if i != j && rooms[i].overlap(&rooms[j]) {
                            bad = true;
                            break;
                        }
                    }
                    if bad {
                        rooms[i].y2 -= 1;
                    }
                }
            }
        }
        rooms
    }
fn grow_rooms ( & mut self , seeds : Vec < Position > , probability : f64 , iterations : i32 ) -> Vec < Room > { let ( w , h ) = ( self . map . width , self . map . height ) ; let mut rng = RandomNumberGenerator :: new ( ) ; let mut rooms = Vec :: new ( ) ; for position in seeds { rooms . push ( Room { x1 : position . x , y1 : position . y , x2 : position . x , y2 : position . y , } ) } for _ in 0 .. iterations { for i in 0 .. rooms . len ( ) { // TODO: find a way of collapsing this, can't access slots by name in structs if rng . range ( 0.0 , 1.0 ) < probability { rooms [ i ] . x1 -= 1 ; if ! rooms [ i ] . in_bounds ( w , h ) { rooms [ i ] . x1 += 1 ; continue ; } let mut bad = false ; for j in 0 .. rooms . len ( ) { if i != j && rooms [ i ] . overlap ( & rooms [ j ] ) { bad = true ; break ; } } if bad { rooms [ i ] . x1 += 1 ; } } if rng . range ( 0.0 , 1.0 ) < probability { rooms [ i ] . y1 -= 1 ; if ! rooms [ i ] . in_bounds ( w , h ) { rooms [ i ] . y1 += 1 ; continue ; } let mut bad = false ; for j in 0 .. rooms . len ( ) { if i != j && rooms [ i ] . overlap ( & rooms [ j ] ) { bad = true ; break ; } } if bad { rooms [ i ] . y1 += 1 ; } } if rng . range ( 0.0 , 1.0 ) < probability { rooms [ i ] . x2 += 1 ; if ! rooms [ i ] . in_bounds ( w , h ) { rooms [ i ] . x2 -= 1 ; continue ; } let mut bad = false ; for j in 0 .. rooms . len ( ) { if i != j && rooms [ i ] . overlap ( & rooms [ j ] ) { bad = true ; break ; } } if bad { rooms [ i ] . x2 -= 1 ; } } if rng . range ( 0.0 , 1.0 ) < probability { rooms [ i ] . y2 += 1 ; if ! rooms [ i ] . in_bounds ( w , h ) { rooms [ i ] . y2 -= 1 ; continue ; } let mut bad = false ; for j in 0 .. rooms . len ( ) { if i != j && rooms [ i ] . overlap ( & rooms [ j ] ) { bad = true ; break ; } } if bad { rooms [ i ] . y2 -= 1 ; } } } } rooms }
Given a list of positions in the map, grow the rooms outwards
Given a list of positions in the map grow the rooms outwards
&mut self
seeds
Vec<Position>
probability
f64
iterations
i32