1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::fmt::Debug;
use compute::{Population, Redis, Updates};
use rustc_serialize::{Decodable, Encodable};
pub trait State: Decodable + Encodable + Debug + Send + Sync + Clone + PartialEq {}
impl<T> State for T where T: Decodable + Encodable + Debug + Send + Sync + Clone + PartialEq {}
pub trait Update
: Decodable + Encodable + Debug + Send + Sync + Clone + PartialEq {
}
impl<T> Update for T where T: Decodable + Encodable + Debug + Send + Sync + Clone + PartialEq {}
#[derive(RustcDecodable, RustcEncodable, Debug, PartialEq, Clone)]
pub struct Agent<S: State> {
pub id: u64,
pub state: S,
}
pub trait Simulation: Sized + Send + Sync + Clone {
type State: State;
type World: State;
type Update: Update;
fn on_spawns<R: Redis>(&self,
agents: Vec<Agent<Self::State>>,
population: &Population<Self, R>)
-> () {
}
fn on_deaths<R: Redis>(&self,
agents: Vec<Agent<Self::State>>,
population: &Population<Self, R>)
-> () {
}
fn decide<R: Redis>(&self,
agent: &Agent<Self::State>,
world: &Self::World,
population: &Population<Self, R>,
updates: &mut Updates<Self>)
-> ();
fn update(&self, state: &mut Self::State, updates: Vec<Self::Update>) -> bool;
fn world_decide<R: Redis>(&self,
world: &Self::World,
population: &Population<Self, R>,
updates: &mut Updates<Self>)
-> () {
}
fn world_update(&self, world: Self::World, updates: Vec<Self::Update>) -> Self::World {
world
}
}