Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More advanced API for finding probabilities via CardDrawTree #6

Open
leun4m opened this issue Jan 15, 2022 · 2 comments
Open

More advanced API for finding probabilities via CardDrawTree #6

leun4m opened this issue Jan 15, 2022 · 2 comments
Projects

Comments

@leun4m
Copy link
Owner

leun4m commented Jan 15, 2022

This is quite a general issue and should be split up into multiple tasks.

Idea is to have the possibility to search through all possible results with:

  • none
  • any
  • all

taking a function as param e.g. Fn(CardDrawSequence) -> bool

@leun4m leun4m created this issue from a note in Version 1 (To do) Jan 15, 2022
@leun4m
Copy link
Owner Author

leun4m commented Jan 15, 2022

Currently all that is necessary to check if a poker deck has only a pair of aces:

fn create_card_deck() -> CardDeck<(&str, &str)> {
    let mut cards = Vec::new();
    for suit in ["♦", "♥", "♠", "♣"] {
        for value in [
            "2", "3", "4", "5", "6", "7", "8", "9", "10", "B", "D", "K", "A",
        ] {
            cards.push((suit, value));
        }
    }
    CardDeck::from(cards)
}

#[test]
fn poker_hand_just_aces() {
    let deck = create_card_deck();
    let tree = CardDrawTree::shrinking(&deck, 2);
    let probability: Probability = tree
        .paths()
        .iter()
        .filter(|seq| {
            seq.cards().iter().all(|card| match card {
                (_, "A") => true,
                _ => false,
            })
        })
        .map(|seq| seq.probability().ratio())
        .sum::<Ratio<u64>>()
        .into();
    assert_eq!(probability, Probability::new(6, 1326));
}

Quite heavy...

@leun4m
Copy link
Owner Author

leun4m commented Sep 22, 2022

Also it should be noted, that this can make use of the graph to get to results more efficiently. For example you don't need to iterate further subnodes if a none is already not fulfilled at the current one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

1 participant