diff --git a/src/board.rs b/src/board.rs index a0afe73..d44cc2c 100644 --- a/src/board.rs +++ b/src/board.rs @@ -1,4 +1,4 @@ -use std::{fmt::Display, num::NonZeroU8}; +use std::fmt::Display; use termion::color; use crate::{Player, Symb}; @@ -134,7 +134,9 @@ impl Board { return false; } - if l.is_some_and(|s| s.is_op()) { + if l.is_some_and(|s| s.is_op()) + || r.is_some_and(|s| s.is_op() && !s.is_minus()) + { return false; } } @@ -253,25 +255,11 @@ impl Board { let x = s .chars() .filter_map(|c| { - let symb = match c { - '+' => Symb::Plus, - '-' => Symb::Minus, - '*' => Symb::Times, - '/' => Symb::Div, - '0' => Symb::Zero, - '1' => Symb::Number(NonZeroU8::new(1).unwrap()), - '2' => Symb::Number(NonZeroU8::new(2).unwrap()), - '3' => Symb::Number(NonZeroU8::new(3).unwrap()), - '4' => Symb::Number(NonZeroU8::new(4).unwrap()), - '5' => Symb::Number(NonZeroU8::new(5).unwrap()), - '6' => Symb::Number(NonZeroU8::new(6).unwrap()), - '7' => Symb::Number(NonZeroU8::new(7).unwrap()), - '8' => Symb::Number(NonZeroU8::new(8).unwrap()), - '9' => Symb::Number(NonZeroU8::new(9).unwrap()), - '_' => return Some(None), - _ => return None, - }; - Some(Some((symb, current_player))) + if let Some(symb) = Symb::from_char(&c) { + Some(Some((symb, current_player))) + } else { + None + } }) .collect::>();