GameSimulator

Struct GameSimulator 

Source
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

Source

pub fn new() -> GameSimulator

Constructor for the GameSimulator struct

§Example
use fbsim_core::game::play::GameSimulator;

let my_sim = GameSimulator::new();
Source

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();
Source

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();
Source

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();
Source

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§

Source§

impl Default for GameSimulator

Source§

fn default() -> Self

Default constructor for the GameSimulator struct

§Example
use fbsim_core::game::play::GameSimulator;

let my_sim = GameSimulator::default();

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> 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, 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