diff --git a/src/block.rs b/src/block.rs index 59ef69a..0a2e2ed 100644 --- a/src/block.rs +++ b/src/block.rs @@ -1,38 +1,45 @@ use action::Action; -use std::vec; +use structure::Structure; -fn make_connections() -> Vec { - vec![0 as f64;9] +pub enum Blocks { + Neuron, + Leg { dir: i32 } } -trait Block { - fn get_connections(&self) -> &Vec; - fn get_value(&self) -> &f64; - fn get_name(&self) -> &'static str; - fn compute(&mut self) -> Vec; - fn clean(&mut self); -} - -struct NeuronBlock { +pub struct Block { + structure: Structure, connections: Vec, current_value: f64, new_value: f64, + block_type: Blocks } -impl Block for NeuronBlock { - fn get_connections(&self) -> &Vec { +impl Block { + pub fn new(structure: Structure, btype: Blocks) -> Block { + Block { + structure: structure, + connections: vec![0 as f64;9], + current_value: 0 as f64, + new_value: 0 as f64, + block_type: btype + } + } + pub fn get_connections(&self) -> &Vec { &self.connections } - fn get_value(&self) -> &f64 { + pub fn get_value(&self) -> &f64 { &self.current_value } - fn get_name(&self) -> &'static str { - "Neuron" + pub fn get_name(&self) -> &'static str { + match self.block_type { + Blocks::Neuron => "Neuron", + Blocks::Leg { dir } => "Leg" + } } - fn compute(&mut self) -> Vec { - Vec::new() + pub fn clean(&mut self) { + self.current_value = self.new_value; } - fn clean(&mut self) { - self.current_value = self.new_value + pub fn compute(&mut self) -> Option> { + None } } diff --git a/src/main.rs b/src/main.rs index e6c9519..c72eff6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ mod util; mod action; mod block; +mod structure; fn main() { println!("Hello, world!"); diff --git a/src/structure.rs b/src/structure.rs index e69de29..889ee60 100644 --- a/src/structure.rs +++ b/src/structure.rs @@ -0,0 +1,27 @@ +use util::Point; +use action::Action; +use block::Block; + +pub struct Structure { + pub blocks: Vec, + pub position: Point +} + +impl Structure { + fn compute(&mut self) -> Vec { + let mut v = Vec::new() as Vec; + // Iterate blocks + for b in &mut self.blocks { + // Compute and save result + let ret = match b.compute() { + Some(x) => x, + None => Vec::new() as Vec + }; + // push actions to the structure's array + for i in ret { + v.push(i) + } + } + v + } +}