Randomize the deck of tiles

This commit is contained in:
2023-02-12 21:01:38 +01:00
parent ea6572dca2
commit 8943d1d898
7 changed files with 194 additions and 13 deletions

View File

@@ -1,15 +1,16 @@
use enum_map::Enum;
use std::fmt;
/// A single digit that can be wrapped in parentheses.
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub struct Digit {
pub value: u8,
pub value: i8,
pub has_left_parenthesis: bool,
pub has_right_parenthesis: bool,
}
impl Digit {
pub fn new(value: u8) -> Self {
pub fn new(value: i8) -> Self {
Self {
value,
has_left_parenthesis: false,
@@ -44,9 +45,9 @@ impl TryFrom<&str> for Digit {
let c = it.next().ok_or(())?;
if c == '(' {
res.has_left_parenthesis = true;
res.value = it.next().ok_or(())?.to_digit(10).ok_or(())? as u8;
res.value = it.next().ok_or(())?.to_digit(10).ok_or(())? as i8;
} else {
res.value = c.to_digit(10).ok_or(())? as u8;
res.value = c.to_digit(10).ok_or(())? as i8;
}
if let Some(c) = it.next() {
if c != ')' {
@@ -59,7 +60,7 @@ impl TryFrom<&str> for Digit {
}
/// An operator that can be applied between two terms.
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[derive(Debug, PartialEq, Eq, Copy, Clone, Enum)]
pub enum Operator {
Add,
Subtract,