nicer looking output
This commit is contained in:
parent
0ebe9e3be3
commit
b437cefe5c
2 changed files with 51 additions and 31 deletions
30
src/dice.rs
30
src/dice.rs
|
|
@ -33,6 +33,8 @@ pub struct DiceFormula {
|
|||
pub(crate) x: bool,
|
||||
}
|
||||
|
||||
const DICE_POOL_LIMIT: usize = 100_000;
|
||||
|
||||
impl Expression {
|
||||
pub fn evaluate(&self, mut rng: impl Rng) -> anyhow::Result<String> {
|
||||
let mut result = String::new();
|
||||
|
|
@ -85,7 +87,7 @@ impl Expression {
|
|||
} else {
|
||||
1
|
||||
};
|
||||
if count > 1_000_000 {
|
||||
if count > DICE_POOL_LIMIT {
|
||||
bail!("Too many dice.")
|
||||
};
|
||||
output.push_str("d");
|
||||
|
|
@ -102,7 +104,7 @@ impl Expression {
|
|||
if size < 2 {
|
||||
bail!("Infinite explosion.")
|
||||
}
|
||||
for i in 0..1_000_000 {
|
||||
for i in 0..DICE_POOL_LIMIT {
|
||||
if i >= rolls.len() {
|
||||
break;
|
||||
}
|
||||
|
|
@ -148,7 +150,7 @@ impl Expression {
|
|||
let print_all_rolls = rolls.len() <= 100;
|
||||
|
||||
if print_all_rolls {
|
||||
output.push_str(" [ ");
|
||||
output.push_str(" ‹ ");
|
||||
}
|
||||
for idx in 0..rolls.len() {
|
||||
let mut skip = false;
|
||||
|
|
@ -174,27 +176,25 @@ impl Expression {
|
|||
skip = true;
|
||||
}
|
||||
}
|
||||
if skip {
|
||||
if print_all_rolls {
|
||||
write!(output, "~~`{}`~~", roll)?;
|
||||
}
|
||||
continue;
|
||||
if !skip {
|
||||
result_set.push(roll as f64);
|
||||
}
|
||||
result_set.push(roll as f64);
|
||||
if print_all_rolls {
|
||||
let bold = size > 2 && (roll == 1 || roll == size);
|
||||
if bold {
|
||||
if skip {
|
||||
write!(output, "~~`{}`~~", roll)?;
|
||||
} else if size > 2 && (roll == 1 || roll == size) {
|
||||
write!(output, "**`{}`**", roll)?;
|
||||
} else {
|
||||
write!(output, "`{}`", roll)?;
|
||||
}
|
||||
|
||||
if idx != rolls.len() - 1 {
|
||||
output.push_str(", ");
|
||||
output.push_str(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
if print_all_rolls {
|
||||
output.push_str(" ]");
|
||||
output.push_str(" ›");
|
||||
}
|
||||
|
||||
result_set.iter().sum()
|
||||
|
|
@ -253,7 +253,7 @@ impl Expression {
|
|||
} else {
|
||||
1
|
||||
};
|
||||
if count > 1_000_000 {
|
||||
if count > DICE_POOL_LIMIT {
|
||||
bail!("Too many dice.")
|
||||
};
|
||||
let size = self.node_sample(rng, *size)? as i64;
|
||||
|
|
@ -268,7 +268,7 @@ impl Expression {
|
|||
if size < 2 {
|
||||
bail!("Infinite explosion.")
|
||||
}
|
||||
for i in 0..1_000_000 {
|
||||
for i in 0..DICE_POOL_LIMIT {
|
||||
if i >= rolls.len() {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue