71 lines
1.6 KiB
Rust
71 lines
1.6 KiB
Rust
use petgraph::graph::{Graph, UnGraph, NodeIndex};
|
|
use petgraph::dot::{Dot, Config};
|
|
|
|
#[derive(Debug,Clone,Copy,PartialEq,Eq,Hash,PartialOrd,Ord,Serialize,Deserialize)]
|
|
pub struct Passive {
|
|
id: &'static str,
|
|
allocated: bool,
|
|
effect: usize,
|
|
}
|
|
|
|
impl Passive {
|
|
fn new(id: &'static str) -> Passive {
|
|
return Passive {
|
|
id,
|
|
allocated: false,
|
|
effect: 0,
|
|
};
|
|
}
|
|
}
|
|
|
|
pub fn create_passive_graph() -> UnGraph<Passive, ()> {
|
|
let mut gr = Graph::new_undirected();
|
|
|
|
let start = gr.add_node(Passive::new("START"));
|
|
let mut last;
|
|
let mut next;
|
|
|
|
// Natural Selection nodes
|
|
next = gr.add_node(Passive::new("NS"));
|
|
gr.add_edge(start, next, ());
|
|
last = next;
|
|
|
|
next = gr.add_node(Passive::new("NSPD0000"));
|
|
gr.add_edge(last, next, ());
|
|
last = next;
|
|
|
|
next = gr.add_node(Passive::new("NSPD0001"));
|
|
gr.add_edge(last, next, ());
|
|
last = next;
|
|
|
|
next = gr.add_node(Passive::new("NSPD0002"));
|
|
gr.add_edge(last, next, ());
|
|
last = next;
|
|
|
|
next = gr.add_node(Passive::new("NSPD0003"));
|
|
gr.add_edge(last, next, ());
|
|
last = next;
|
|
|
|
next = gr.add_node(Passive::new("NSBLOCK"));
|
|
gr.add_edge(last, next, ());
|
|
last = next;
|
|
|
|
return gr;
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use passives::*;
|
|
|
|
#[test]
|
|
fn create_graph() {
|
|
let _graph = create_passive_graph();
|
|
// good shit;
|
|
// let nodes = graph.node_indices().collect::<Vec<NodeIndex>>();
|
|
// info!("{:?}", nodes[0]);
|
|
// info!("{:?}", graph.node_weight(nodes[0]));
|
|
|
|
// info!("{:?}", Dot::with_config(&graph, &[Config::EdgeNoLabel]));
|
|
}
|
|
}
|