Compare commits

..

7 Commits

21 changed files with 302 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
01.workspace/target

148
01.workspace/Cargo.lock generated Normal file
View File

@@ -0,0 +1,148 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "getrandom"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasip2",
]
[[package]]
name = "libc"
version = "0.2.177"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
[[package]]
name = "oxydice_lib"
version = "0.1.0"
dependencies = [
"rand",
]
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "rand"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
]
[[package]]
name = "syn"
version = "2.0.110"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "wasip2"
version = "1.0.1+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "wit-bindgen"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]]
name = "zerocopy"
version = "0.8.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831"
dependencies = [
"proc-macro2",
"quote",
"syn",
]

3
01.workspace/Cargo.toml Normal file
View File

@@ -0,0 +1,3 @@
[workspace]
resolver = "3"
members = ["oxydice_lib"]

View File

@@ -0,0 +1,7 @@
[package]
name = "oxydice_lib"
version = "0.1.0"
edition = "2024"
[dependencies]
rand = "0.9.2"

View File

@@ -0,0 +1,6 @@
use oxydice_lib::*;
fn main() {
let mut dice = dice::Dice::grab(3, 6);
dice.roll();
}

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,20 @@
use crate::*;
impl Dice {
pub fn grab(dice: u16, sides: u16) -> Self {
let mut handful = Vec::<Die>::new();
for _ in 1..=dice {
handful.push(Die::new(sides));
}
Self {
handful,
..Self::default()
}
}
pub fn and_grab(mut self, dice: u16, sides: u16) -> Self {
for _ in 1..=dice {
self.handful.push(Die::new(sides));
}
self
}
}

View File

@@ -0,0 +1,10 @@
use crate::*;
impl Dice {
pub fn roll(&mut self) {
self.result.die_results.clear();
for die in &self.handful {
self.result.die_results.push(die.roll());
}
}
}

View File

@@ -0,0 +1,7 @@
use crate::*;
impl Die {
pub fn new(sides: u16) -> Die {
Self { sides }
}
}

View File

@@ -0,0 +1,8 @@
use crate::*;
impl Die {
pub fn roll(&self) -> u16 {
let mut rng = rand::rng();
rng.random_range(0..self.sides)
}
}

View File

@@ -0,0 +1,4 @@
pub mod dice_grab;
pub mod dice_roll;
pub mod die_new;
pub mod die_roll;

View File

@@ -0,0 +1,18 @@
use std::*;
use rand::*;
mod fun;
mod imp;
mod mcr;
mod str;
mod trt;
mod tst;
pub(crate) use crate::str::dice::O as Dice;
pub(crate) use crate::str::die::O as Die;
pub(crate) use crate::str::roll_result::O as RollResult;
pub mod dice {
pub use crate::str::dice::O as Dice;
}

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,7 @@
use crate::*;
#[derive(Debug, Default, PartialEq, Clone)]
pub struct O {
pub(crate) handful: Vec<Die>,
pub(crate) result: RollResult,
}

View File

@@ -0,0 +1,6 @@
use crate::*;
#[derive(Debug, Default, PartialEq, Clone)]
pub struct O {
pub(crate) sides: u16,
}

View File

@@ -0,0 +1,3 @@
pub mod dice;
pub mod die;
pub mod roll_result;

View File

@@ -0,0 +1,6 @@
use crate::*;
#[derive(Debug, Default, PartialEq, Clone)]
pub struct O {
pub(crate) die_results: Vec<u16>,
}

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,23 @@
#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn dice_grab_should_create_a_new_handful_of_dice() {
let dice_handful = Dice::grab(3, 6);
assert_eq!(dice_handful.handful.len(), 3);
for die in dice_handful.handful {
assert_eq!(die.sides, 6);
}
}
#[test]
fn test_dice_and_grab_should_add_more_dice_to_handful() {
let initial_dice = Dice::grab(2, 6);
let initial_count = initial_dice.handful.len();
let new_dice_handful = initial_dice.and_grab(2, 8);
assert_eq!(new_dice_handful.handful.len(), initial_count + 2);
// Check the sides of the newly added dice
for i in initial_count..new_dice_handful.handful.len() {
assert_eq!(new_dice_handful.handful[i].sides, 8);
}
}
}

View File

@@ -0,0 +1,20 @@
#[cfg(test)]
mod tests {
use crate::*;
#[test]
pub fn dice_roll_should_yield_always_the_proper_number_of_result() {
let mut dice = Dice::grab(3, 6);
for _ in 1..=1000 {
dice.roll();
assert_eq!(dice.result.die_results.len(), 3);
}
}
#[test]
pub fn dice_roll_should_yield_valid_results() {
let mut dice = Dice::grab(3, 6);
for _ in 1..=10000 {
dice.roll();
assert!(dice.result.die_results[0] < 6);
}
}
}

View File

@@ -0,0 +1,2 @@
pub mod dice_grab;
pub mod dice_roll;