GameContext

Struct GameContext 

Source
pub struct GameContext { /* private fields */ }
Expand description

§GameContext struct

A GameContext represents a game scenario

Implementations§

Source§

impl GameContext

Source

pub fn new() -> GameContext

Constructor for the GameContext class where properties are defaulted

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
Source

pub fn home_team_short(&self) -> &str

Borrow the GameContext home team short property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let home_team_short = my_context.home_team_short();
assert!(home_team_short == "HOME");
Source

pub fn away_team_short(&self) -> &str

Borrow the GameContext away team short property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let away_team_short = my_context.away_team_short();
assert!(away_team_short == "AWAY");
Source

pub fn quarter(&self) -> u32

Borrow the GameContext quarter property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let quarter = my_context.quarter();
assert!(quarter == 1);
Source

pub fn half_seconds(&self) -> u32

Borrow the GameContext half_seconds property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let half_seconds = my_context.half_seconds();
assert!(half_seconds == 1800);
Source

pub fn down(&self) -> u32

Borrow the GameContext down property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let down = my_context.down();
assert!(down == 0);
Source

pub fn distance(&self) -> u32

Borrow the GameContext distance property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let distance = my_context.distance();
assert!(distance == 10);
Source

pub fn yard_line(&self) -> u32

Borrow the GameContext yard_line property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let yard_line = my_context.yard_line();
assert!(yard_line == 35);
Source

pub fn home_score(&self) -> u32

Borrow the GameContext home_score property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let home_score = my_context.home_score();
assert!(home_score == 0);
Source

pub fn away_score(&self) -> u32

Borrow the GameContext away_score property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let away_score = my_context.away_score();
assert!(away_score == 0);
Source

pub fn home_timeouts(&self) -> u32

Borrow the GameContext home_timeouts property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let home_timeouts = my_context.home_timeouts();
assert!(home_timeouts == 3);
Source

pub fn away_timeouts(&self) -> u32

Borrow the GameContext away_timeouts property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let away_timeouts = my_context.away_timeouts();
assert!(away_timeouts == 3);
Source

pub fn home_possession(&self) -> bool

Borrow the GameContext home_possession property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let home_possession = my_context.home_possession();
assert!(home_possession);
Source

pub fn home_positive_direction(&self) -> bool

Borrow the GameContext home_positive_direction property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let home_positive_direction = my_context.home_positive_direction();
assert!(home_positive_direction);
Source

pub fn home_opening_kickoff(&self) -> bool

Borrow the GameContext home_opening_kickoff property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let home_opening_kickoff = my_context.home_opening_kickoff();
assert!(home_opening_kickoff);
Source

pub fn last_play_turnover(&self) -> bool

Borrow the GameContext last_play_turnover property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let last_play_turnover = my_context.last_play_turnover();
assert!(!last_play_turnover);
Source

pub fn last_play_incomplete(&self) -> bool

Borrow the GameContext last_play_incomplete property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let last_play_incomplete = my_context.last_play_incomplete();
assert!(!last_play_incomplete);
Source

pub fn last_play_out_of_bounds(&self) -> bool

Borrow the GameContext last_play_out_of_bounds property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let last_play_out_of_bounds = my_context.last_play_out_of_bounds();
assert!(!last_play_out_of_bounds);
Source

pub fn last_play_kickoff(&self) -> bool

Borrow the GameContext last_play_kickoff property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let last_play_kickoff = my_context.last_play_kickoff();
assert!(!last_play_kickoff);
Source

pub fn last_play_punt(&self) -> bool

Borrow the GameContext last_play_punt property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let last_play_punt = my_context.last_play_punt();
assert!(!last_play_punt);
Source

pub fn last_play_timeout(&self) -> bool

Borrow the GameContext last_play_timeout property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let last_play_timeout = my_context.last_play_timeout();
assert!(!last_play_timeout);
Source

pub fn next_play_kickoff(&self) -> bool

Borrow the GameContext next_play_kickoff property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let next_play_kickoff = my_context.next_play_kickoff();
assert!(next_play_kickoff);
Source

pub fn next_play_extra_point(&self) -> bool

Borrow the GameContext next_play_extra_point property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let next_play_extra_point = my_context.next_play_extra_point();
assert!(!next_play_extra_point);
Source

pub fn end_of_half(&self) -> bool

Borrow the GameContext end_of_half property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let end_of_half = my_context.end_of_half();
assert!(!end_of_half);
Source

pub fn game_over(&self) -> bool

Borrow the GameContext game_over property

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let game_over = my_context.game_over();
assert!(!game_over);
Source

pub fn defense_timeouts(&self) -> u32

Get the number of timeouts the defense has left

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let defense_timeouts = my_context.defense_timeouts();
assert!(defense_timeouts == 3);
Source

pub fn offense_timeouts(&self) -> u32

Get the number of timeouts the offense has left

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let offense_timeouts = my_context.offense_timeouts();
assert!(offense_timeouts == 3);
Source

pub fn clock_running(&self) -> bool

Determine whether the clock is running

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let clock_running = my_context.clock_running();
assert!(!clock_running);
Source

pub fn yards_to_touchdown(&self) -> i32

Get the yards remaining until the defense’s goal line

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let yards_to_touchdown = my_context.yards_to_touchdown();
assert!(yards_to_touchdown == 65_i32);
Source

pub fn yards_to_safety(&self) -> i32

Get the yards remaining until the offense’s goal line

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::new();
let yards_to_safety = my_context.yards_to_safety();
assert!(yards_to_safety == -35_i32);
Source

pub fn next_home_score(&self, update_opts: &GameContextUpdateOptions) -> u32

Get the updated home score

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.off_score = ScoreResult::Touchdown;
let my_context = GameContext::new();
let home_score = my_context.next_home_score(&update_opts);
assert!(home_score == 6);
Source

pub fn next_away_score(&self, update_opts: &GameContextUpdateOptions) -> u32

Get the updated away score

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.def_score = ScoreResult::Safety;
let my_context = GameContext::new();
let away_score = my_context.next_away_score(&update_opts);
assert!(away_score == 2);
Source

pub fn next_score_tied(&self, update_opts: &GameContextUpdateOptions) -> bool

Determine whether the score is tied given the scoring results from the last play

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let update_opts = GameContextUpdateOptions::default();
let my_context = GameContext::new();
let score_tied = my_context.next_score_tied(&update_opts);
assert!(score_tied);
Source

pub fn next_half_seconds(&self, update_opts: &GameContextUpdateOptions) -> u32

Get the updated half seconds

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.duration = 10;
let my_context = GameContext::new();
let half_seconds = my_context.next_half_seconds(&update_opts);
assert!(half_seconds == 1790);
Source

pub fn next_end_of_half(&self, update_opts: &GameContextUpdateOptions) -> bool

Get the updated end of half property

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.duration = 10;
let my_context = GameContext::new();
let end_of_half = my_context.next_end_of_half(&update_opts);
assert!(!end_of_half);
Source

pub fn next_game_over(&self, update_opts: &GameContextUpdateOptions) -> bool

Get the updated game over property

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.duration = 10;
let my_context = GameContext::new();
let game_over = my_context.next_game_over(&update_opts);
assert!(!game_over);
Source

pub fn next_quarter(&self, update_opts: &GameContextUpdateOptions) -> u32

Get the updated quarter

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.duration = 10;
let my_context = GameContext::new();
let quarter = my_context.next_quarter(&update_opts);
assert!(quarter == 1);
Source

pub fn next_home_positive_direction( &self, update_opts: &GameContextUpdateOptions, ) -> bool

Get the updated home team direction

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.duration = 10;
let my_context = GameContext::new();
let next_home_positive_direction = my_context.next_home_positive_direction(&update_opts);
assert!(next_home_positive_direction);
Source

pub fn next_down(&self, update_opts: &GameContextUpdateOptions) -> u32

Get the updated down

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.net_yards = 10;
update_opts.turnover = true;
let my_context = GameContext::new();
let down = my_context.next_down(&update_opts);
assert!(down == 1);
Source

pub fn next_home_possession( &self, update_opts: &GameContextUpdateOptions, ) -> bool

Get the updated home possession property

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.net_yards = 10;
let my_context = GameContext::new();
let next_home_possession = my_context.next_home_possession(&update_opts);
assert!(!next_home_possession);
Source

pub fn next_yard_line(&self, update_opts: &GameContextUpdateOptions) -> u32

Get the updated yard line

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.net_yards = 10;
let my_context = GameContext::new();
let yard_line = my_context.next_yard_line(&update_opts);
assert!(yard_line == 45);
Source

pub fn next_distance(&self, update_opts: &GameContextUpdateOptions) -> u32

Get the updated distance

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
use fbsim_core::game::play::result::ScoreResult;

let mut update_opts = GameContextUpdateOptions::default();
update_opts.net_yards = 10;
let my_context = GameContext::new();
let distance = my_context.next_distance(&update_opts);
assert!(distance == 10);
Source

pub fn next_home_timeouts(&self, update_opts: &GameContextUpdateOptions) -> u32

Get the updated home timetous

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.off_timeout = true;
let my_context = GameContext::new();
let next_home_timeouts = my_context.next_home_timeouts(&update_opts);
assert!(next_home_timeouts == 2);
Source

pub fn next_away_timeouts(&self, update_opts: &GameContextUpdateOptions) -> u32

Get the updated away timetous

§Example
use fbsim_core::game::context::{GameContext, GameContextUpdateOptions};
 
let mut update_opts = GameContextUpdateOptions::default();
update_opts.def_timeout = true;
let my_context = GameContext::new();
let next_away_timeouts = my_context.next_away_timeouts(&update_opts);
assert!(next_away_timeouts == 2);
Source

pub fn next_context(&self, result: &(impl PlayResult + ?Sized)) -> GameContext

Get the next context given the results of the previous play

Trait Implementations§

Source§

impl Clone for GameContext

Source§

fn clone(&self) -> GameContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GameContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GameContext

Source§

fn default() -> Self

Default constructor for the GameContext class

§Example
use fbsim_core::game::context::GameContext;
 
let my_context = GameContext::default();
Source§

impl<'de> Deserialize<'de> for GameContext

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for GameContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format a GameContext as a string.

§Example
use fbsim_core::game::context::GameContext;

// Initialize a game context and display it
let my_context = GameContext::new();
println!("{}", my_context);
Source§

impl From<&GameContext> for PlayContext

Source§

fn from(item: &GameContext) -> PlayContext

Initialize a PlayContext from a borrowed GameContext

§Example
use fbsim_core::game::context::GameContext;
use fbsim_core::game::play::context::PlayContext;
 
let game_context = GameContext::new();
let play_context = PlayContext::from(&game_context);
Source§

impl Ord for GameContext

Source§

fn cmp(&self, other: &GameContext) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for GameContext

Source§

fn eq(&self, other: &GameContext) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for GameContext

Source§

fn partial_cmp(&self, other: &GameContext) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for GameContext

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<GameContextRaw> for GameContext

Source§

type Error = String

The type returned in the event of a conversion error.
Source§

fn try_from(item: GameContextRaw) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for GameContext

Source§

impl StructuralPartialEq for GameContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,