Skip to main content

example/
example.rs

1#![allow(clippy::unwrap_used, clippy::expect_used)]
2
3use event_simulation::Simulation;
4use multilinear::{Change, MultilinearInfo, MultilinearSimulation};
5
6fn main() {
7    let mut story = MultilinearInfo::new();
8
9    // Create aspects
10    let place = story.add_aspect();
11    let clothes = story.add_aspect();
12
13    // Define event: Move from bedroom to living room
14    let event_move = story
15        .add_event()
16        .with_change(&[Change::transition(place, 0, 1)])
17        .unwrap()
18        .event();
19
20    // Define event: Change clothes in bedroom
21    let event_clothes = story
22        .add_event()
23        .with_change(&[
24            Change::condition(place, 0),
25            Change::transition(clothes, 1, 0),
26        ])
27        .unwrap()
28        .event();
29
30    let mut simulation = MultilinearSimulation::new(story);
31    simulation.try_call(event_clothes);
32    simulation.try_call(event_move);
33    simulation.try_revert(event_move);
34}