Skip to content

Commit 889cdcb

Browse files
authored
Merge pull request #62 from folkengine/bcm2
Sped up bcrepl
2 parents 6c52754 + cf1cca0 commit 889cdcb

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "pkcore"
33
description = "Prototype core poker library."
4-
version = "0.0.28"
4+
version = "0.0.29"
55
rust-version = "1.91.0"
66
edition = "2024"
77
authors = ["electronicpanopticon <gaoler@electronicpanopticon.com>"]

examples/bcrepl.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use pkcore::PKError;
22
use pkcore::play::stages::deal_eval::DealEval;
33
use pkcore::prelude::HoleCards;
44
use pkcore::util::terminal::Terminal;
5+
use std::collections::HashMap;
56

67
/// OK, this makes me sad. My new shiny pkcore library takes over twice as long to run a single calc
78
///
@@ -27,14 +28,15 @@ use pkcore::util::terminal::Terminal;
2728
/// `A♠ A♥ A♦ A♣`
2829
fn main() {
2930
env_logger::init();
31+
let mut cache: HashMap<HoleCards, DealEval> = HashMap::new();
3032
loop {
31-
read_input();
33+
read_input(&mut cache);
3234
}
3335
}
3436

35-
fn read_input() {
37+
fn read_input(cache: &mut HashMap<HoleCards, DealEval>) {
3638
match Terminal::receive_cards_in_twos("hole cards> ") {
37-
Ok(twos) => match work(twos) {
39+
Ok(twos) => match work(twos, cache) {
3840
Ok(_) => {}
3941
Err(e) => println!("{:?}", e),
4042
},
@@ -44,18 +46,12 @@ fn read_input() {
4446
}
4547
}
4648

47-
fn work(hands: HoleCards) -> Result<(), PKError> {
49+
fn work(hands: HoleCards, cache: &mut HashMap<HoleCards, DealEval>) -> Result<(), PKError> {
4850
let now = std::time::Instant::now();
4951

50-
let results = DealEval::new(hands);
52+
let results = cache.entry(hands).or_insert_with_key(|h| DealEval::new(h.clone()));
5153

52-
// let case_events = hands.bcm_case_evals()?;
53-
// let case_events = hands.bcm_case_evals()?;
54-
// let case_events = hands.bcm_rayon_case_evals()?;
55-
// let wins = case_events.wins();
56-
// let results = WinResults::from_wins(&wins, hands.len());
5754
println!("{results}");
58-
5955
println!("Elapsed: {:.2?}", now.elapsed());
6056
Ok(())
6157
}

src/play/hole_cards.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use std::vec::IntoIter;
4747
/// is fleeting.
4848
///
4949
/// TODO: Refactor to Two;
50-
#[derive(Clone, Debug, Default, Eq, PartialEq)]
50+
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
5151
pub struct HoleCards(Vec<Two>);
5252

5353
impl HoleCards {

0 commit comments

Comments
 (0)