the implementation carries on
This commit is contained in:
parent
0004fa2acf
commit
5005bc17cf
49
src/block.rs
49
src/block.rs
@ -1,38 +1,45 @@
|
||||
use action::Action;
|
||||
use std::vec;
|
||||
use structure::Structure;
|
||||
|
||||
fn make_connections() -> Vec<f64> {
|
||||
vec![0 as f64;9]
|
||||
pub enum Blocks {
|
||||
Neuron,
|
||||
Leg { dir: i32 }
|
||||
}
|
||||
|
||||
trait Block {
|
||||
fn get_connections(&self) -> &Vec<f64>;
|
||||
fn get_value(&self) -> &f64;
|
||||
fn get_name(&self) -> &'static str;
|
||||
fn compute(&mut self) -> Vec<Action>;
|
||||
fn clean(&mut self);
|
||||
}
|
||||
|
||||
struct NeuronBlock {
|
||||
pub struct Block {
|
||||
structure: Structure,
|
||||
connections: Vec<f64>,
|
||||
current_value: f64,
|
||||
new_value: f64,
|
||||
block_type: Blocks
|
||||
}
|
||||
|
||||
impl Block for NeuronBlock {
|
||||
fn get_connections(&self) -> &Vec<f64> {
|
||||
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<f64> {
|
||||
&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<Action> {
|
||||
Vec::new()
|
||||
}
|
||||
fn clean(&mut self) {
|
||||
self.current_value = self.new_value
|
||||
pub fn clean(&mut self) {
|
||||
self.current_value = self.new_value;
|
||||
}
|
||||
pub fn compute(&mut self) -> Option<Vec<Action>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
mod util;
|
||||
mod action;
|
||||
mod block;
|
||||
mod structure;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
|
@ -0,0 +1,27 @@
|
||||
use util::Point;
|
||||
use action::Action;
|
||||
use block::Block;
|
||||
|
||||
pub struct Structure {
|
||||
pub blocks: Vec<Block>,
|
||||
pub position: Point
|
||||
}
|
||||
|
||||
impl Structure {
|
||||
fn compute(&mut self) -> Vec<Action> {
|
||||
let mut v = Vec::new() as Vec<Action>;
|
||||
// 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<Action>
|
||||
};
|
||||
// push actions to the structure's array
|
||||
for i in ret {
|
||||
v.push(i)
|
||||
}
|
||||
}
|
||||
v
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user