fn gen_pos(snake: &Snake, bounds: Bounds) -> Vec2 {
        loop {
            // Initializes the random number generator (RNG).
            let mut rng = rand::thread_rng();
            // Generates a random point.
            let point = Vec2 {
                x: rng.gen_range(bounds.min.x, bounds.max.x + 1),
                y: rng.gen_range(bounds.min.y, bounds.max.y + 1),
            };

            let valid = !snake.contains(point);

            if valid {
                // Only stops if the point is not contained by the snake.
                break point;
            }
        }
    }
/// Generates a random position for the food, such that it is inside of the
/// bounds, and it is not at the same place as the snake.
Generates a random position for the food, such that it is inside of the
bounds, and it is not at the same place as the snake.
Generates a random position for the food such that it is inside of the bounds and it is not at the same place as the snake .
fn gen_pos(snake: &Snake, bounds: Bounds) -> Vec2 {
        loop {
            // Initializes the random number generator (RNG).
            let mut rng = rand::thread_rng();
            // Generates a random point.
            let point = Vec2 {
                x: rng.gen_range(bounds.min.x, bounds.max.x + 1),
                y: rng.gen_range(bounds.min.y, bounds.max.y + 1),
            };
            let valid = !snake.contains(point);
            if valid {
                // Only stops if the point is not contained by the snake.
                break point;
            }
        }
    }
fn gen_pos ( snake : & Snake , bounds : Bounds ) -> Vec2 { loop { // Initializes the random number generator (RNG). let mut rng = rand :: thread_rng ( ) ; // Generates a random point. let point = Vec2 { x : rng . gen_range ( bounds . min . x , bounds . max . x + 1 ) , y : rng . gen_range ( bounds . min . y , bounds . max . y + 1 ) , } ; let valid = ! snake . contains ( point ) ; if valid { // Only stops if the point is not contained by the snake. break point ; } } }
Generates a random position for the food, such that it is inside of the
bounds, and it is not at the same place as the snake.
Generates a random position for the food such that it is inside of the bounds and it is not at the same place as the snake .
snake
&Snake
bounds
Bounds
snake
&Snake
bounds
Bounds