1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Camel Up is a game of chance.
//!
//! 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.
//!
//! # Example
//! To determine who has the better winning chance of two camels, where one camel has fallen two behind one could use the following code.
//!
//! ```
//! use camel_up::prelude::*;
//! let race = "r,,w".parse::<Race>().expect("to parse");
//! let dice = "rw".parse::<Dice>().expect("to parse");
//!
//! let result = project(&race, &dice);
//! let red_chance = result.winner[&Camel::Red];
//! let white_chance = result.winner[&Camel::White];
//!
//! assert!(white_chance > red_chance);
//! ```
//!
//! ## Parsing of Race
//! As the above example shows one can parse a string and get a `Race`. The following table describes each symbol.alloc
//!
//! | Symbol | Marker |
//! |--------|-------------|
//! | r | Red |
//! | o | Orange |
//! | y | Yellow |
//! | g | Green |
//! | w | White |
//! | , | Divider |
//! | + | Oasis |
//! | - | FataMorgana |
//!
//! 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.
//!
//! ```
//! use camel_up::camel::*;
//! assert_eq!("r|y".parse::<Race>(), Err(RaceParseError::NotAMarker(NotAMarker::But("|".to_owned()))));
//! assert_eq!("+r,y".parse::<Race>(), Err(RaceParseError::CamelInOasis));
//! assert_eq!("-r,y".parse::<Race>(), Err(RaceParseError::CamelInFataMorgana));
//! assert_eq!("r,-+,y".parse::<Race>(), Err(RaceParseError::ToManyAdjustmentsInOnePosition));
//! assert_eq!("r,-,+,y".parse::<Race>(), Err(RaceParseError::ConsecutiveAdjustments));
//! ```
//!
//! ## Parsing of Dice
//! Dice can be similarly parsed. The only allowed symbols are the ones for the camels.