Circles and spirals in mind
This commit is contained in:
parent
17cadfe2fd
commit
f0dbc0cbe2
1 changed files with 24 additions and 0 deletions
24
src/node/node_modifier.rs
Normal file
24
src/node/node_modifier.rs
Normal 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 }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue