This commit is contained in:
132nd-Professor
2022-08-11 20:29:17 +02:00
parent 1a2a08515b
commit 84f1bf7efe
8 changed files with 391 additions and 244 deletions
+52
View File
@@ -0,0 +1,52 @@
use std::collections::HashSet;
#[derive(PartialEq, Clone)]
pub enum Coalition {
Blue,
Red,
Purple,
All,
Unknown,
}
impl Coalition {
pub fn from_line<S: AsRef<str>>(line: &S) -> Self {
let line = line.as_ref();
if line.contains("Color=Blue") {
Self::Blue
} else if line.contains("Color=Red") {
Self::Red
} else if line.contains("Color=Purple") {
Self::Purple
} else {
Self::Unknown
}
}
pub fn line_contains_coalition<S: AsRef<str>>(line: &S) -> bool {
line.as_ref().contains("Color=")
}
}
pub struct CoalitionIDs<'a> {
pub blue: HashSet<&'a str>,
pub red: HashSet<&'a str>,
pub purple: HashSet<&'a str>,
}
impl<'a> CoalitionIDs<'a> {
pub fn new() -> Self {
let (blue, red, purple) = (HashSet::new(), HashSet::new(), HashSet::new());
Self { blue, red, purple }
}
pub fn insert(&mut self, id: &'a str, coalition: Coalition) {
match coalition {
Coalition::Blue => self.blue.insert(id),
Coalition::Red => self.red.insert(id),
Coalition::Purple => self.purple.insert(id),
Coalition::All => false,
Coalition::Unknown => false,
};
}
}