pub struct GameContext { /* private fields */ }Expand description
§GameContext struct
A GameContext represents a game scenario
Implementations§
Source§impl GameContext
impl GameContext
Sourcepub fn new() -> GameContext
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();Sourcepub fn home_team_short(&self) -> &str
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");Sourcepub fn away_team_short(&self) -> &str
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");Sourcepub fn quarter(&self) -> u32
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);Sourcepub fn half_seconds(&self) -> u32
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);Sourcepub fn down(&self) -> u32
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);Sourcepub fn distance(&self) -> u32
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);Sourcepub fn yard_line(&self) -> u32
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);Sourcepub fn home_score(&self) -> u32
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);Sourcepub fn away_score(&self) -> u32
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);Sourcepub fn home_timeouts(&self) -> u32
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);Sourcepub fn away_timeouts(&self) -> u32
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);Sourcepub fn home_possession(&self) -> bool
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);Sourcepub fn home_positive_direction(&self) -> bool
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);Sourcepub fn home_opening_kickoff(&self) -> bool
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);Sourcepub fn last_play_turnover(&self) -> bool
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);Sourcepub fn last_play_incomplete(&self) -> bool
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);Sourcepub fn last_play_out_of_bounds(&self) -> bool
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);Sourcepub fn last_play_kickoff(&self) -> bool
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);Sourcepub fn last_play_punt(&self) -> bool
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);Sourcepub fn last_play_timeout(&self) -> bool
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);Sourcepub fn next_play_kickoff(&self) -> bool
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);Sourcepub fn next_play_extra_point(&self) -> bool
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);Sourcepub fn end_of_half(&self) -> bool
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);Sourcepub fn game_over(&self) -> bool
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);Sourcepub fn defense_timeouts(&self) -> u32
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);Sourcepub fn offense_timeouts(&self) -> u32
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);Sourcepub fn clock_running(&self) -> bool
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);Sourcepub fn yards_to_touchdown(&self) -> i32
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);Sourcepub fn yards_to_safety(&self) -> i32
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);Sourcepub fn next_home_score(&self, update_opts: &GameContextUpdateOptions) -> u32
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);Sourcepub fn next_away_score(&self, update_opts: &GameContextUpdateOptions) -> u32
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);Sourcepub fn next_score_tied(&self, update_opts: &GameContextUpdateOptions) -> bool
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);Sourcepub fn next_half_seconds(&self, update_opts: &GameContextUpdateOptions) -> u32
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);Sourcepub fn next_end_of_half(&self, update_opts: &GameContextUpdateOptions) -> bool
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);Sourcepub fn next_game_over(&self, update_opts: &GameContextUpdateOptions) -> bool
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);Sourcepub fn next_quarter(&self, update_opts: &GameContextUpdateOptions) -> u32
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);Sourcepub fn next_home_positive_direction(
&self,
update_opts: &GameContextUpdateOptions,
) -> bool
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);Sourcepub fn next_down(&self, update_opts: &GameContextUpdateOptions) -> u32
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);Sourcepub fn next_home_possession(
&self,
update_opts: &GameContextUpdateOptions,
) -> bool
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);Sourcepub fn next_yard_line(&self, update_opts: &GameContextUpdateOptions) -> u32
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);Sourcepub fn next_distance(&self, update_opts: &GameContextUpdateOptions) -> u32
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);Sourcepub fn next_home_timeouts(&self, update_opts: &GameContextUpdateOptions) -> u32
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);Sourcepub fn next_away_timeouts(&self, update_opts: &GameContextUpdateOptions) -> u32
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);Sourcepub fn next_context(&self, result: &(impl PlayResult + ?Sized)) -> GameContext
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
impl Clone for GameContext
Source§fn clone(&self) -> GameContext
fn clone(&self) -> GameContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GameContext
impl Debug for GameContext
Source§impl Default for GameContext
impl Default for GameContext
Source§impl<'de> Deserialize<'de> for GameContext
impl<'de> Deserialize<'de> for GameContext
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for GameContext
impl Display for GameContext
Source§impl From<&GameContext> for PlayContext
impl From<&GameContext> for PlayContext
Source§fn from(item: &GameContext) -> PlayContext
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
impl Ord for GameContext
Source§fn cmp(&self, other: &GameContext) -> Ordering
fn cmp(&self, other: &GameContext) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for GameContext
impl PartialEq for GameContext
Source§impl PartialOrd for GameContext
impl PartialOrd for GameContext
Source§impl Serialize for GameContext
impl Serialize for GameContext
Source§impl TryFrom<GameContextRaw> for GameContext
impl TryFrom<GameContextRaw> for GameContext
impl Eq for GameContext
impl StructuralPartialEq for GameContext
Auto Trait Implementations§
impl Freeze for GameContext
impl RefUnwindSafe for GameContext
impl Send for GameContext
impl Sync for GameContext
impl Unpin for GameContext
impl UnwindSafe for GameContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.