[][src]Struct connect6::agent::AsyncAgent

pub struct AsyncAgent<P: 'static + Policy + Send, F: Fn() -> P> { /* fields omitted */ }

Agent for playing multiple games asynchronously.

AsyncAgent play multiple games on tokio thread-pool. It pass the policy generator and return the vector of game result.

Examples

let policy_gen = || RandomPolicy::new();
let async_agent = AsyncAgent::debug(policy_gen);

let result = async_agent.run(4);
println!("ratio: {}", result.iter().map(|x| x.winner as i32).sum::<i32>());

Methods

impl<P: 'static + Policy + Send, F: Fn() -> P> AsyncAgent<P, F>[src]

pub fn new(policy_gen: F) -> AsyncAgent<P, F>[src]

Construct a new AsyncAgent.

Get policy generator as callable object which return impl Policy.

Examples

let gen = || RandomPolicy::new();
let async_agent = AsyncAgent::new(gen);

pub fn debug(policy_gen: F) -> AsyncAgent<P, F>[src]

Construct a debug mode AsyncAgent, it will display the dbg info.

Examples

let gen = || RandomPolicy::new();
let async_agent = AsyncAgent::debug(gen);

pub fn run(&self, num: i32) -> Vec<PlayResult>[src]

Self-play the given number of games asynchronously on thread pool.

Examples

let gen = || RandomPolicy::new();
let async_agent = AsyncAgent::new(gen);

let result = async_agent.run(4);
println!("result: {}", result.iter().map(|x| x.winner as i32).sum::<i32>());

Panics

If some games return the Err from Agent::play.

Auto Trait Implementations

impl<P, F> Send for AsyncAgent<P, F> where
    F: Send

impl<P, F> Sync for AsyncAgent<P, F> where
    F: Sync

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T