Minor tweaks

master
Mark 2024-03-03 22:09:57 -08:00
parent 7a3249e766
commit 35f6682b8d
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
1 changed files with 9 additions and 21 deletions

View File

@ -1,4 +1,4 @@
use std::{fmt::Display, num::NonZeroU8}; use std::fmt::Display;
use termion::color; use termion::color;
use crate::{Player, Symb}; use crate::{Player, Symb};
@ -134,7 +134,9 @@ impl Board {
return false; 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; return false;
} }
} }
@ -253,25 +255,11 @@ impl Board {
let x = s let x = s
.chars() .chars()
.filter_map(|c| { .filter_map(|c| {
let symb = match c { if let Some(symb) = Symb::from_char(&c) {
'+' => Symb::Plus, Some(Some((symb, current_player)))
'-' => Symb::Minus, } else {
'*' => Symb::Times, None
'/' => 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)))
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();