pub struct Strategies<'a, Infoset, Action> { /* private fields */ }Expand description
A compact strategy for both players
Strategies are tied to a specific game and maintain a reference back to them. Create these from original data using Game::from_named.
Implementations§
Source§impl<'a, I, A> Strategies<'a, I, A>
impl<'a, I, A> Strategies<'a, I, A>
Sourcepub fn as_named<'b: 'a>(&'b self) -> [NamedStrategyIter<'a, I, A>; 2]
pub fn as_named<'b: 'a>(&'b self) -> [NamedStrategyIter<'a, I, A>; 2]
Attach player, infoset, and action information to a strategy
Use this to convert a strategy profile into an exportable format.
§Examples
let game = // ...
let (strats, _) = game.solve(
// ...
).unwrap();
let [player_one_strat, player_two_strat] = strats.as_named();
for (infoset, actions) in player_one_strat {
for (action, prob) in actions {
// ...
}
}Examples found in repository?
172fn main() {
173 let args = Args::parse();
174 let game = create_kuhn(args.num_cards);
175 let (mut strats, _) = game
176 .solve(
177 SolveMethod::External,
178 args.iterations,
179 0.0,
180 args.parallel,
181 None,
182 )
183 .unwrap();
184 strats.truncate(5e-3); // not visible
185 let [player_one_strat, player_two_strat] = strats.as_named();
186 println!("Player One");
187 println!("==========");
188 let mut init = Vec::with_capacity(3);
189 let mut raised = Vec::with_capacity(3);
190 for (&(card, raise), actions) in player_one_strat {
191 if raise { &mut raised } else { &mut init }.push((card, actions));
192 }
193 println!("Initial Action");
194 println!("--------------");
195 print_card_strat(init, args.num_cards);
196 println!("If Player Two Raised");
197 println!("--------------------");
198 print_card_strat(raised, args.num_cards);
199 println!("Player Two");
200 println!("==========");
201 let mut called = Vec::with_capacity(3);
202 let mut raised = Vec::with_capacity(3);
203 for (&(card, raise), actions) in player_two_strat {
204 if raise { &mut raised } else { &mut called }.push((card, actions));
205 }
206 println!("If Player One Called");
207 println!("--------------------");
208 print_card_strat(called, args.num_cards);
209 println!("If Player One Raised");
210 println!("--------------------");
211 print_card_strat(raised, args.num_cards);
212}Sourcepub fn truncate(&mut self, thresh: f64)
pub fn truncate(&mut self, thresh: f64)
Truncate actions with small probability
Since CFR produces approximate equilibria, often it will return a strategy with very low
probability of playing an action that should never actually be played. Use this to truncate
the probability of small actions when they’re played less than thresh of the time.
Examples found in repository?
172fn main() {
173 let args = Args::parse();
174 let game = create_kuhn(args.num_cards);
175 let (mut strats, _) = game
176 .solve(
177 SolveMethod::External,
178 args.iterations,
179 0.0,
180 args.parallel,
181 None,
182 )
183 .unwrap();
184 strats.truncate(5e-3); // not visible
185 let [player_one_strat, player_two_strat] = strats.as_named();
186 println!("Player One");
187 println!("==========");
188 let mut init = Vec::with_capacity(3);
189 let mut raised = Vec::with_capacity(3);
190 for (&(card, raise), actions) in player_one_strat {
191 if raise { &mut raised } else { &mut init }.push((card, actions));
192 }
193 println!("Initial Action");
194 println!("--------------");
195 print_card_strat(init, args.num_cards);
196 println!("If Player Two Raised");
197 println!("--------------------");
198 print_card_strat(raised, args.num_cards);
199 println!("Player Two");
200 println!("==========");
201 let mut called = Vec::with_capacity(3);
202 let mut raised = Vec::with_capacity(3);
203 for (&(card, raise), actions) in player_two_strat {
204 if raise { &mut raised } else { &mut called }.push((card, actions));
205 }
206 println!("If Player One Called");
207 println!("--------------------");
208 print_card_strat(called, args.num_cards);
209 println!("If Player One Raised");
210 println!("--------------------");
211 print_card_strat(raised, args.num_cards);
212}Sourcepub fn distance(&self, other: &Self, p: f64) -> [f64; 2]
pub fn distance(&self, other: &Self, p: f64) -> [f64; 2]
Get the distance between this strategy and another strategy
This computes the avg of the l-p earth movers distance between the strategies for each
player, thus the value is between 0 and 1 where 0 represents identical strategies, and 1
represents strategies that share no support.
This is only a valid distance if p is at least 1, which should also be the default
setting.
§Panics
Panics if other isn’t from the same game, or if p isn’t positive
Sourcepub fn get_info(&self) -> StrategiesInfo
pub fn get_info(&self) -> StrategiesInfo
Get regret and utility information for this strategy profile
Trait Implementations§
Source§impl<'a, Infoset: Clone, Action: Clone> Clone for Strategies<'a, Infoset, Action>
impl<'a, Infoset: Clone, Action: Clone> Clone for Strategies<'a, Infoset, Action>
Source§fn clone(&self) -> Strategies<'a, Infoset, Action>
fn clone(&self) -> Strategies<'a, Infoset, Action>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<I, A> PartialEq for Strategies<'_, I, A>
Strategies are equal if they contain identical values and are from the same game
impl<I, A> PartialEq for Strategies<'_, I, A>
Strategies are equal if they contain identical values and are from the same game
Equality is strict since action probabilities can’t be nan.
impl<I, A> Eq for Strategies<'_, I, A>
Auto Trait Implementations§
impl<'a, Infoset, Action> Freeze for Strategies<'a, Infoset, Action>
impl<'a, Infoset, Action> RefUnwindSafe for Strategies<'a, Infoset, Action>where
Infoset: RefUnwindSafe,
Action: RefUnwindSafe,
impl<'a, Infoset, Action> Send for Strategies<'a, Infoset, Action>
impl<'a, Infoset, Action> Sync for Strategies<'a, Infoset, Action>
impl<'a, Infoset, Action> Unpin for Strategies<'a, Infoset, Action>
impl<'a, Infoset, Action> UnwindSafe for Strategies<'a, Infoset, Action>where
Infoset: RefUnwindSafe,
Action: RefUnwindSafe,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more