fn random_maze(width: usize, height: usize) -> Vec<Tile> {
    let mut tiles = vec![Tile::Wall; width * height];
    let mut rng = thread_rng();
    let mut stack = Vec::new();
    stack.push((0, 0));
    while !stack.is_empty() {
        // we can unwrap because we know that the stack isn't empty
        let pos = stack.last().unwrap().clone();
        tiles[pos.0 * width + pos.1] = Tile::Floor;
        let valid = valid_tiles(pos, (height, width), &tiles);
        match rng.choose(&valid) {
            // There are valid position lefts, and we start searching from that position
            Some(new_pos) => { stack.push(*new_pos) }
            // There are no valid positions left, so we go back to the previous one
            None => { stack.pop(); }
        }
    }
    tiles
}
/// Generates a random maze, through depth first search
Generates a random maze, through depth first search
Generates a random maze through depth first search
fn random_maze(width: usize, height: usize) -> Vec<Tile> {
    let mut tiles = vec![Tile::Wall; width * height];
    let mut rng = thread_rng();
    let mut stack = Vec::new();
    stack.push((0, 0));
    while !stack.is_empty() {
        // we can unwrap because we know that the stack isn't empty
        let pos = stack.last().unwrap().clone();
        tiles[pos.0 * width + pos.1] = Tile::Floor;
        let valid = valid_tiles(pos, (height, width), &tiles);
        match rng.choose(&valid) {
            // There are valid position lefts, and we start searching from that position
            Some(new_pos) => { stack.push(*new_pos) }
            // There are no valid positions left, so we go back to the previous one
            None => { stack.pop(); }
        }
    }
    tiles
}
fn random_maze ( width : usize , height : usize ) -> Vec < Tile > { let mut tiles = vec ! [ Tile Wall width height ] ; let mut rng = thread_rng ( ) ; let mut stack = Vec :: new ( ) ; stack . push ( ( 0 , 0 ) ) ; while ! stack . is_empty ( ) { // we can unwrap because we know that the stack isn't empty let pos = stack . last ( ) . unwrap ( ) . clone ( ) ; tiles [ pos . 0 * width + pos . 1 ] = Tile :: Floor ; let valid = valid_tiles ( pos , ( height , width ) , & tiles ) ; match rng . choose ( & valid ) { // There are valid position lefts, and we start searching from that position Some ( new_pos ) => { stack . push ( * new_pos ) } // There are no valid positions left, so we go back to the previous one None => { stack . pop ( ) ; } } } tiles }
Generates a random maze, through depth first search
Generates a random maze through depth first search
width
usize
height
usize
width
usize
height
usize