-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutcome.rs
51 lines (44 loc) · 1.55 KB
/
outcome.rs
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
//! Outcome data types
use std::collections::HashMap;
use std::fmt::Display;
use serde::{Deserialize, Serialize};
use crate::allyset::AllySet;
use crate::decision::DecisionPath;
/// [`HashMap`] of [`Outcome`]s to [metadata][DecisionPathMetadata] describing the [`DecisionPath`]s
/// from which they were produced
pub type OutcomeMap = HashMap<Outcome, DecisionPathMetadata>;
/// Result of one or more complete decision paths
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Outcome {
/// Allies who survived the final mission
pub survivors: AllySet,
/// Loyal allies who survived the final mission
pub loyal: AllySet,
/// Was the crew of _The Normandy_ rescued?
pub rescued_crew: bool,
}
impl Display for Outcome {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
writeln!(f, "Survivors: {}", self.survivors)?;
write!(f, "Loyal: ")?;
if self.loyal.len() == self.survivors.len() {
writeln!(f, "all survivors")?;
} else {
writeln!(f, "{}", self.loyal)?;
}
let past_tense_verb = if self.rescued_crew {
"rescued"
} else {
"abandoned"
};
writeln!(f, "The crew was {past_tense_verb}.")
}
}
/// [`OutcomeMap`] value
#[derive(Debug, Deserialize, Serialize)]
pub struct DecisionPathMetadata {
/// Number of distinct decision paths that led to the same [`Outcome`]
pub count: usize,
/// One example of a decision path that led to an [`Outcome`]
pub example: DecisionPath,
}