|
|
@ -1,17 +1,25 @@
|
|
|
|
use board_shared::position::Position2d;
|
|
|
|
use board_shared::{
|
|
|
|
use board_shared::tile::{Digit, Operator, Tile};
|
|
|
|
board::Board,
|
|
|
|
|
|
|
|
position::{Grid2d, Position2d},
|
|
|
|
|
|
|
|
tile::{Digit, Operator, Tile},
|
|
|
|
|
|
|
|
};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
#[serde(remote = "Tile")]
|
|
|
|
pub struct BoardRef {
|
|
|
|
|
|
|
|
pub tiles: Vec<Option<TileRef>>,
|
|
|
|
|
|
|
|
pub width: usize,
|
|
|
|
|
|
|
|
pub height: usize,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub enum TileRef {
|
|
|
|
pub enum TileRef {
|
|
|
|
Digit(#[serde(with = "DigitRef")] Digit),
|
|
|
|
Digit(DigitRef),
|
|
|
|
Operator(#[serde(with = "OperatorRef")] Operator),
|
|
|
|
Operator(OperatorRef),
|
|
|
|
Equals,
|
|
|
|
Equals,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
#[serde(remote = "Digit")]
|
|
|
|
|
|
|
|
pub struct DigitRef {
|
|
|
|
pub struct DigitRef {
|
|
|
|
pub value: i8,
|
|
|
|
pub value: i8,
|
|
|
|
pub has_left_parenthesis: bool,
|
|
|
|
pub has_left_parenthesis: bool,
|
|
|
@ -19,7 +27,6 @@ pub struct DigitRef {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
#[serde(remote = "Operator")]
|
|
|
|
|
|
|
|
pub enum OperatorRef {
|
|
|
|
pub enum OperatorRef {
|
|
|
|
Add,
|
|
|
|
Add,
|
|
|
|
Subtract,
|
|
|
|
Subtract,
|
|
|
@ -28,8 +35,69 @@ pub enum OperatorRef {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
#[serde(remote = "Position2d")]
|
|
|
|
|
|
|
|
pub struct Position2dRef {
|
|
|
|
pub struct Position2dRef {
|
|
|
|
pub x: usize,
|
|
|
|
pub x: usize,
|
|
|
|
pub y: usize,
|
|
|
|
pub y: usize,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<&Board> for BoardRef {
|
|
|
|
|
|
|
|
fn from(value: &Board) -> Self {
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
tiles: value
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(|tile| tile.map(Into::into))
|
|
|
|
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
|
|
|
|
width: value.width(),
|
|
|
|
|
|
|
|
height: value.height(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Tile> for TileRef {
|
|
|
|
|
|
|
|
fn from(value: Tile) -> Self {
|
|
|
|
|
|
|
|
match value {
|
|
|
|
|
|
|
|
Tile::Digit(digit) => TileRef::Digit(digit.into()),
|
|
|
|
|
|
|
|
Tile::Operator(operator) => TileRef::Operator(operator.into()),
|
|
|
|
|
|
|
|
Tile::Equals => TileRef::Equals,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Digit> for DigitRef {
|
|
|
|
|
|
|
|
fn from(value: Digit) -> Self {
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
value: value.value,
|
|
|
|
|
|
|
|
has_left_parenthesis: value.has_left_parenthesis,
|
|
|
|
|
|
|
|
has_right_parenthesis: value.has_right_parenthesis,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Operator> for OperatorRef {
|
|
|
|
|
|
|
|
fn from(value: Operator) -> Self {
|
|
|
|
|
|
|
|
match value {
|
|
|
|
|
|
|
|
Operator::Add => OperatorRef::Add,
|
|
|
|
|
|
|
|
Operator::Subtract => OperatorRef::Subtract,
|
|
|
|
|
|
|
|
Operator::Multiply => OperatorRef::Multiply,
|
|
|
|
|
|
|
|
Operator::Divide => OperatorRef::Divide,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Position2d> for Position2dRef {
|
|
|
|
|
|
|
|
fn from(value: Position2d) -> Self {
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
x: value.x,
|
|
|
|
|
|
|
|
y: value.y,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Position2dRef> for Position2d {
|
|
|
|
|
|
|
|
fn from(value: Position2dRef) -> Self {
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
x: value.x,
|
|
|
|
|
|
|
|
y: value.y,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|