use dcfr::{
kuhn::{History, Kuhn},
lcfr::{expected_value, TabularLcfr},
};
use indicatif::ProgressIterator;
use itertools::Itertools;
use rand::SeedableRng;
use rand_pcg::Pcg64Mcg;
fn main() {
let game = Kuhn::<2>::new();
let mut cfr_trainer = TabularLcfr::new();
let mut rng = Pcg64Mcg::seed_from_u64(4);
for _ in (0..100000).progress() {
cfr_trainer.single_iter(&game, &mut rng);
}
for ((p, info_set), ss) in &cfr_trainer.strategy_sum {
let sum: f32 = ss.iter().sum();
let (s1, s2) = ss.iter().map(|s| s / sum).collect_tuple().unwrap();
let info_set_str = info_set
.iter()
.flatten()
.map(History::concise_repr)
.join(" ");
println!("{s1:.4} {s2:.4} {p:.2} [{info_set_str}]");
}
println!(
"evs = {:?}",
expected_value(
game,
&|player, infoset| {
let strat = &cfr_trainer.strategy_sum[&(player, infoset.clone())];
let s_sum: f32 = strat.iter().sum();
strat.iter().map(|s| s / s_sum).collect()
},
&mut rng
)
);
}