1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- use rand::{ distributions:: {Distribution, Standard},
- Rng
- };
-
- #[derive(Debug)]
- enum Cls {
- Artificer,
- Barbarian,
- Bard,
- Cleric,
- Druid,
- Fighter,
- Monk,
- Paladin,
- Ranger,
- Rogue,
- Sorcerer,
- Warlock,
- Wizard
- }
-
- impl Default for Cls {
- fn default() -> Self { Cls::Fighter }
- }
-
- impl Distribution<Cls> for Standard {
- fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Cls {
- match rng.gen_range(0..=12) {
- 0 => Cls::Artificer,
- 1 => Cls::Barbarian,
- 2 => Cls::Bard,
- 3 => Cls::Cleric,
- 4 => Cls::Druid,
- 5 => Cls::Fighter,
- 6 => Cls::Monk,
- 7 => Cls::Paladin,
- 8 => Cls::Ranger,
- 9 => Cls::Rogue,
- 10 => Cls::Sorcerer,
- 11 => Cls::Warlock,
- 12 => Cls::Wizard,
- _ => Cls::Fighter
- }
- }
- }
-
- #[derive(Debug, Default)]
- struct Character {
- cls: Cls,
- strength: u32,
- dexterity: u32,
- constitution: u32,
- intelligence: u32,
- wisdom: u32,
- charisma: u32,
- }
-
- // impl Character {
-
- // }
-
- fn roll_stat() -> u32 {
- let mut rolls = Vec::new();
- while rolls.len()<4 {
- let roll = rand::thread_rng().gen_range(1..=6);
- if roll == 1 {
- continue;
- }
- rolls.push(roll);
- }
- println!("{:?}", rolls);
- rolls.sort_by(|a,b| b.cmp(a));
- println!("{:?}", rolls);
- rolls.pop();
- println!("{:?}", rolls);
- rolls.iter().sum()
- }
-
- fn main() {
- let mut chr: Character = Default::default();
- chr.cls = rand::random();
- chr.strength = roll_stat();
- chr.dexterity = roll_stat();
- chr.constitution = roll_stat();
- chr.intelligence = roll_stat();
- chr.wisdom = roll_stat();
- chr.charisma = roll_stat();
- println!("{:?}", chr);
- }
|