Circles and spirals in mind

This commit is contained in:
Rendo 2025-11-06 21:35:28 +05:00
commit f0dbc0cbe2

24
src/node/node_modifier.rs Normal file
View file

@ -0,0 +1,24 @@
use crate::node::Node;
use rand::random_range;
const PICK_STOP_PROBABILITY: u8 = 2;
pub struct NodeModifier<'a> {
picked_node: &'a mut Node,
}
impl<'a> NodeModifier<'a> {
pub fn from_random(root: &'a mut Node) -> NodeModifier<'a> {
let mut selected = root;
while random_range(0..PICK_STOP_PROBABILITY) == PICK_STOP_PROBABILITY - 1 {
let len = selected.children.len();
selected = &mut selected.children[random_range(0..len)];
}
NodeModifier {
picked_node: selected,
}
}
pub fn from_node(node: &'a mut Node) -> NodeModifier<'a> {
NodeModifier { picked_node: node }
}
}