Add benchmark
This commit is contained in:
parent
6eb184c6ae
commit
25b0004822
4 changed files with 70 additions and 5 deletions
|
|
@ -42,7 +42,7 @@ fn run_simulation(view: &Arc<Mutex<Option<TerminalView<impl Backend>>>>) {
|
|||
agents.push(((x, y).into(), Box::new(SimpleAgent)));
|
||||
}
|
||||
}
|
||||
let mut world = ActualWorld::new((width, height).into(), agents);
|
||||
let mut world = ActualWorld::new((width, height).into(), agents, true);
|
||||
|
||||
let mut gen = 0;
|
||||
loop {
|
||||
|
|
|
|||
18
src/world.rs
18
src/world.rs
|
|
@ -5,6 +5,7 @@ pub struct ActualWorld {
|
|||
size: Position,
|
||||
pub agents: HashMap<AgentId, Box<dyn Agent>>,
|
||||
pub state: WorldState,
|
||||
validating: bool,
|
||||
}
|
||||
|
||||
pub struct WorldState {
|
||||
|
|
@ -16,7 +17,11 @@ pub struct WorldState {
|
|||
impl ActualWorld {
|
||||
/// Agents receive incrementing ids starting with 0
|
||||
/// The last agent is 'It'
|
||||
pub fn new(size: Position, input_agents: Vec<(Position, Box<dyn Agent>)>) -> Self {
|
||||
pub fn new(
|
||||
size: Position,
|
||||
input_agents: Vec<(Position, Box<dyn Agent>)>,
|
||||
validating: bool,
|
||||
) -> Self {
|
||||
let agent_count = input_agents.len();
|
||||
assert!(agent_count > 0);
|
||||
let mut id = 0;
|
||||
|
|
@ -36,6 +41,7 @@ impl ActualWorld {
|
|||
size,
|
||||
agents,
|
||||
state,
|
||||
validating,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,8 +83,9 @@ impl ActualWorld {
|
|||
tagged_by: self.state.tagged_by,
|
||||
};
|
||||
for (id, mv) in moves {
|
||||
self.check_move(id, &mv);
|
||||
//println!("{} {:?}", id, mv);
|
||||
if self.validating {
|
||||
self.check_move(id, &mv);
|
||||
}
|
||||
let mut new_pos = None;
|
||||
match mv {
|
||||
Move::Noop => {}
|
||||
|
|
@ -135,7 +142,7 @@ mod test {
|
|||
#[test]
|
||||
#[should_panic]
|
||||
fn empty() {
|
||||
ActualWorld::new(Position { x: 0, y: 0 }, vec![]);
|
||||
ActualWorld::new(Position { x: 0, y: 0 }, vec![], true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -143,6 +150,7 @@ mod test {
|
|||
let mut world = ActualWorld::new(
|
||||
Position { x: 0, y: 0 },
|
||||
vec![(Position { x: 0, y: 0 }, Box::new(NullAgent))],
|
||||
true,
|
||||
);
|
||||
world.do_step();
|
||||
assert_eq!(world.state.tagged, 0);
|
||||
|
|
@ -163,6 +171,7 @@ mod test {
|
|||
Box::new(ScriptedAgent::new(vec![Move::TryTag(0)])),
|
||||
),
|
||||
],
|
||||
true,
|
||||
);
|
||||
world.do_step();
|
||||
assert_eq!(world.state.tagged, 0);
|
||||
|
|
@ -178,6 +187,7 @@ mod test {
|
|||
Position { x: 0, y: 0 },
|
||||
Box::new(ScriptedAgent::new(vec![Move::TryMove((-1, -1).into())])),
|
||||
)],
|
||||
true,
|
||||
);
|
||||
world.do_step();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue