Finish tasks to bring calculation capabilities in line with last interval. #9
@@ -1,5 +1,4 @@
|
|||||||
use crate::{Play, Team, TerrainState};
|
use crate::{Down, Play, Team, TerrainState, error};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
type Offence = Team;
|
type Offence = Team;
|
||||||
@@ -13,6 +12,56 @@ pub enum Event {
|
|||||||
Score(ScorePoints),
|
Score(ScorePoints),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Event {
|
||||||
|
pub fn delta(&self, following: &Self) -> Option<i8> {
|
||||||
|
// Clean this trash spaghetti code up.
|
||||||
|
|
||||||
|
fn make_play(event: &Event) -> Option<Play> {
|
||||||
|
match event {
|
||||||
|
Event::Kickoff(_) => Some(Play::default()),
|
||||||
|
Event::Play(play) => {
|
||||||
|
let p = play.to_owned();
|
||||||
|
|
||||||
|
if p.down.is_none()
|
||||||
|
|| p.terrain.is_none()
|
||||||
|
|| p.terrain.as_ref()? == &TerrainState::Unknown
|
||||||
|
{
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let preceeding = make_play(self)?;
|
||||||
|
let following = make_play(following)?;
|
||||||
|
|
||||||
|
if following.down? == Down::First {
|
||||||
|
if let TerrainState::Yards(yrds) = preceeding.terrain? {
|
||||||
|
Some(yrds as i8)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let a = if let TerrainState::Yards(yrds) = preceeding.terrain? {
|
||||||
|
yrds
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
|
||||||
|
let b = if let TerrainState::Yards(yrds) = following.terrain? {
|
||||||
|
yrds
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
|
||||||
|
Some((a - b) as i8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone, PartialEq)]
|
#[derive(Debug, Deserialize, Clone, PartialEq)]
|
||||||
pub enum ScorePoints {
|
pub enum ScorePoints {
|
||||||
Touchdown,
|
Touchdown,
|
||||||
|
|||||||
@@ -6,13 +6,7 @@ pub trait PlayHandle {
|
|||||||
fn plays(&self) -> Vec<Play>;
|
fn plays(&self) -> Vec<Play>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Distance {
|
#[derive(Debug, Deserialize, Clone, PartialEq)]
|
||||||
fn distance(&self) -> u8;
|
|
||||||
|
|
||||||
fn delta<D: Distance>(&self, d: D);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone, Default, PartialEq)]
|
|
||||||
pub struct Play {
|
pub struct Play {
|
||||||
pub action: Action,
|
pub action: Action,
|
||||||
pub down: Option<Down>,
|
pub down: Option<Down>,
|
||||||
@@ -25,13 +19,13 @@ impl PlayHandle for Play {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Distance for Play {
|
impl Default for Play {
|
||||||
fn distance(&self) -> u8 {
|
fn default() -> Self {
|
||||||
todo!()
|
Self {
|
||||||
}
|
action: Action::default(),
|
||||||
|
down: Some(Down::First),
|
||||||
fn delta<D: Distance>(&self, d: D) {
|
terrain: Some(TerrainState::Yards(10)),
|
||||||
todo!()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user