pub struct DriveSimulator { /* private fields */ }Expand description
§DriveSimulator struct
A DriveSimulator can simulate a drive given a context, returning an
updated context and a drive
Implementations§
Source§impl DriveSimulator
impl DriveSimulator
Sourcepub fn new() -> DriveSimulator
pub fn new() -> DriveSimulator
Initialize a new drive simulator
§Example
use fbsim_core::game::play::DriveSimulator;
let my_sim = DriveSimulator::new();Sourcepub fn sim_play(
&self,
home: &FootballTeam,
away: &FootballTeam,
context: GameContext,
drive: &mut Drive,
rng: &mut impl Rng,
) -> Result<GameContext, String>
pub fn sim_play( &self, home: &FootballTeam, away: &FootballTeam, context: GameContext, drive: &mut Drive, rng: &mut impl Rng, ) -> Result<GameContext, String>
Simulate the next play of a drive
§Example
use fbsim_core::game::context::GameContext;
use fbsim_core::game::play::{Drive, DriveSimulator};
use fbsim_core::team::FootballTeam;
// Initialize home & away teams
let my_home = FootballTeam::new();
let my_away = FootballTeam::new();
// Initialize a game context
let mut my_context = GameContext::new();
let mut drive = Drive::new();
// Initialize a drive simulator & simulate a drive
let my_sim = DriveSimulator::new();
let mut rng = rand::thread_rng();
my_context = my_sim.sim_play(&my_home, &my_away, my_context, &mut drive, &mut rng).unwrap();Sourcepub fn sim_drive(
&self,
home: &FootballTeam,
away: &FootballTeam,
context: GameContext,
drive: &mut Drive,
rng: &mut impl Rng,
) -> Result<GameContext, String>
pub fn sim_drive( &self, home: &FootballTeam, away: &FootballTeam, context: GameContext, drive: &mut Drive, rng: &mut impl Rng, ) -> Result<GameContext, String>
Simulate the remaining plays of a drive
§Example
use fbsim_core::game::context::GameContext;
use fbsim_core::game::play::{Drive, DriveSimulator};
use fbsim_core::team::FootballTeam;
// Initialize home & away teams
let my_home = FootballTeam::new();
let my_away = FootballTeam::new();
// Initialize a game context
let my_context = GameContext::new();
// Initialize a drive simulator & simulate a drive
let mut my_drive = Drive::new();
let my_sim = DriveSimulator::new();
let mut rng = rand::thread_rng();
let next_context = my_sim.sim_drive(&my_home, &my_away, my_context, &mut my_drive, &mut rng).unwrap();Sourcepub fn sim(
&self,
home: &FootballTeam,
away: &FootballTeam,
context: GameContext,
rng: &mut impl Rng,
) -> (Drive, GameContext)
pub fn sim( &self, home: &FootballTeam, away: &FootballTeam, context: GameContext, rng: &mut impl Rng, ) -> (Drive, GameContext)
Simulate a new drive
§Example
use fbsim_core::game::context::GameContext;
use fbsim_core::game::play::DriveSimulator;
use fbsim_core::team::FootballTeam;
// Initialize home & away teams
let my_home = FootballTeam::new();
let my_away = FootballTeam::new();
// Initialize a game context
let my_context = GameContext::new();
// Initialize a drive simulator & simulate a drive
let my_sim = DriveSimulator::new();
let mut rng = rand::thread_rng();
let (drive, next_context) = my_sim.sim(&my_home, &my_away, my_context, &mut rng);Trait Implementations§
Auto Trait Implementations§
impl Freeze for DriveSimulator
impl RefUnwindSafe for DriveSimulator
impl Send for DriveSimulator
impl Sync for DriveSimulator
impl Unpin for DriveSimulator
impl UnwindSafe for DriveSimulator
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
Mutably borrows from an owned value. Read more
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.