pub struct GameSimulator { /* private fields */ }Expand description
§GameSimulator struct
A GameSimulator can simulate a game given a context, returning an
updated context and a drive
Implementations§
Source§impl GameSimulator
impl GameSimulator
Sourcepub fn new() -> GameSimulator
pub fn new() -> GameSimulator
Constructor for the GameSimulator struct
§Example
use fbsim_core::game::play::GameSimulator;
let my_sim = GameSimulator::new();Sourcepub fn sim_play(
&self,
home: &FootballTeam,
away: &FootballTeam,
context: GameContext,
game: &mut Game,
rng: &mut impl Rng,
) -> Result<GameContext, String>
pub fn sim_play( &self, home: &FootballTeam, away: &FootballTeam, context: GameContext, game: &mut Game, rng: &mut impl Rng, ) -> Result<GameContext, String>
Simulate the next play of a game
§Example
use fbsim_core::game::context::GameContext;
use fbsim_core::game::play::{GameSimulator, Game};
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 game simulator & simulate a drive
let mut my_game = Game::new();
let my_sim = GameSimulator::new();
let mut rng = rand::thread_rng();
let next_context = my_sim.sim_play(&my_home, &my_away, my_context, &mut my_game, &mut rng).unwrap();Sourcepub fn sim_drive(
&self,
home: &FootballTeam,
away: &FootballTeam,
context: GameContext,
game: &mut Game,
rng: &mut impl Rng,
) -> Result<GameContext, String>
pub fn sim_drive( &self, home: &FootballTeam, away: &FootballTeam, context: GameContext, game: &mut Game, rng: &mut impl Rng, ) -> Result<GameContext, String>
Simulate the next drive of a game
§Example
use fbsim_core::game::context::GameContext;
use fbsim_core::game::play::{GameSimulator, Game};
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 game simulator & simulate a drive
let mut my_game = Game::new();
let my_sim = GameSimulator::new();
let mut rng = rand::thread_rng();
let next_context = my_sim.sim_drive(&my_home, &my_away, my_context, &mut my_game, &mut rng).unwrap();Sourcepub fn sim_game(
&self,
home: &FootballTeam,
away: &FootballTeam,
context: GameContext,
game: &mut Game,
rng: &mut impl Rng,
) -> Result<GameContext, String>
pub fn sim_game( &self, home: &FootballTeam, away: &FootballTeam, context: GameContext, game: &mut Game, rng: &mut impl Rng, ) -> Result<GameContext, String>
Simulate the remainder of a game
§Example
use fbsim_core::game::context::GameContext;
use fbsim_core::game::play::{GameSimulator, Game};
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 game simulator and game, simulate the game
let mut my_game = Game::new();
let my_sim = GameSimulator::new();
let mut rng = rand::thread_rng();
let next_context = my_sim.sim_game(&my_home, &my_away, my_context, &mut my_game, &mut rng).unwrap();Sourcepub fn sim(
&self,
home: &FootballTeam,
away: &FootballTeam,
context: GameContext,
rng: &mut impl Rng,
) -> Result<(Game, GameContext), String>
pub fn sim( &self, home: &FootballTeam, away: &FootballTeam, context: GameContext, rng: &mut impl Rng, ) -> Result<(Game, GameContext), String>
Simulate a new game
§Example
use fbsim_core::game::context::GameContext;
use fbsim_core::game::play::GameSimulator;
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 game simulator & simulate a game
let my_sim = GameSimulator::new();
let mut rng = rand::thread_rng();
let (game, final_context) = my_sim.sim(&my_home, &my_away, my_context, &mut rng).unwrap();Trait Implementations§
Auto Trait Implementations§
impl Freeze for GameSimulator
impl RefUnwindSafe for GameSimulator
impl Send for GameSimulator
impl Sync for GameSimulator
impl Unpin for GameSimulator
impl UnwindSafe for GameSimulator
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.