doc
This commit is contained in:
parent
8dbaf597c9
commit
6fe5a268da
5 changed files with 229 additions and 37 deletions
|
|
@ -4,15 +4,11 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
/// Represents the two dices
|
||||
///
|
||||
/// Backgammon is always played with two dices.
|
||||
/// Trictrac is always played with two dices.
|
||||
#[derive(Debug, Clone, Copy, Serialize, PartialEq, Deserialize, Default)]
|
||||
pub struct Dices {
|
||||
/// The two dice values
|
||||
pub values: (u8, u8),
|
||||
/// Boolean indicating whether the dices have been consumed already. We use a tuple
|
||||
/// of four booleans in case the dices are equal, in which case we have four dices
|
||||
/// to play.
|
||||
pub consumed: (bool, bool, bool, bool),
|
||||
}
|
||||
impl Dices {
|
||||
/// Roll the dices which generates two random numbers between 1 and 6, replicating a perfect
|
||||
|
|
@ -23,17 +19,8 @@ impl Dices {
|
|||
|
||||
let v = (between.sample(&mut rng), between.sample(&mut rng));
|
||||
|
||||
// if both dices are equal, we have four dices to play
|
||||
if v.0 == v.1 {
|
||||
Dices {
|
||||
values: (v.0, v.1),
|
||||
consumed: (false, false, false, false),
|
||||
}
|
||||
} else {
|
||||
Dices {
|
||||
values: (v.0, v.1),
|
||||
consumed: (false, false, true, true),
|
||||
}
|
||||
Dices {
|
||||
values: (v.0, v.1),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -55,25 +42,4 @@ mod tests {
|
|||
assert!(dices.values.1 >= 1 && dices.values.1 <= 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_roll_consumed() {
|
||||
let dices = Dices::default().roll();
|
||||
if dices.values.0 == dices.values.1 {
|
||||
assert_eq!(dices.consumed, (false, false, false, false));
|
||||
} else {
|
||||
assert_eq!(dices.consumed, (false, false, true, true));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_roll_consumed1() {
|
||||
for _i in 0..100 {
|
||||
let dices = Dices::default().roll();
|
||||
if dices.values.0 == dices.values.1 {
|
||||
assert_eq!(dices.consumed, (false, false, false, false));
|
||||
} else {
|
||||
assert_eq!(dices.consumed, (false, false, true, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,6 +108,12 @@ impl GameState {
|
|||
pos_bits.append(&mut step_bits.into());
|
||||
|
||||
// dice roll -> 4 bits
|
||||
let mut dice_bits = match self.dices {
|
||||
TurnStage::RollDice => [false, false],
|
||||
TurnStage::MarkPoints => [false, true],
|
||||
TurnStage::Move => [true, false],
|
||||
};
|
||||
pos_bits.append(&mut step_bits.into());
|
||||
// points 10bits x2 joueurs = 20bits
|
||||
// * points -> 4bits
|
||||
// * trous -> 4bits
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue