camel_up/
lib.rs

1#![deny(missing_docs)]
2//! Camel Up is a game of chance.
3//!
4//! Since probability questions are often very hard. This crate provides an oracle to answer questions concerning which camel will come out ahead in the race.
5//!
6//! # Example
7//! To determine who has the better winning chance of two camels, where one camel has fallen two behind one could use the following code.
8//!
9//! ```
10//! use camel_up::prelude::*;
11//! let race = "r,,w".parse::<Race>().expect("to parse");
12//! let dice = "rw".parse::<Dice>().expect("to parse");
13//!
14//! let result = project(&race, &dice);
15//! let red_chance = result.winner[&Camel::Red];
16//! let white_chance = result.winner[&Camel::White];
17//!
18//! assert!(white_chance > red_chance);
19//! ```
20//!
21//! ## Parsing of Race
22//! As the above example shows one can parse a string and get a `Race`. The following table describes each symbol.alloc
23//!
24//! | Symbol | Marker      |
25//! |--------|-------------|
26//! | r      | Red         |
27//! | o      | Orange      |
28//! | y      | Yellow      |
29//! | g      | Green       |
30//! | w      | White       |
31//! | ,      | Divider     |
32//! | +      | Oasis       |
33//! | -      | FataMorgana |
34//!
35//! As per the rules of the game, camels can not be in a oasis or a fata morgana, nor can either of those be next to each other. So the following strings all fail to parse.
36//!
37//! ```
38//! use camel_up::camel::*;
39//! assert_eq!("r|y".parse::<Race>(), Err(RaceParseError::NotAMarker(NotAMarker::But("|".to_owned()))));
40//! assert_eq!("+r,y".parse::<Race>(), Err(RaceParseError::CamelInOasis));
41//! assert_eq!("-r,y".parse::<Race>(), Err(RaceParseError::CamelInFataMorgana));
42//! assert_eq!("r,-+,y".parse::<Race>(), Err(RaceParseError::ToManyAdjustmentsInOnePosition));
43//! assert_eq!("r,-,+,y".parse::<Race>(), Err(RaceParseError::ConsecutiveAdjustments));
44//! ```
45//! 
46//! ## Parsing of Dice
47//! Dice can be similarly parsed. The only allowed symbols are the ones for the camels.
48
49pub mod camel;
50pub mod fraction;
51pub mod oracle;
52mod tree;
53
54pub mod prelude {
55    //! Easy access to a good combination of camel up related concepts.
56
57    pub use crate::camel::{Camel, Dice, Race};
58    pub use crate::fraction::Fraction;
59    pub use crate::oracle::project;
60}