Skip to content

Commit

Permalink
Add missing serde implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
t4ccer committed Nov 13, 2023
1 parent a606ad1 commit 6fdb7c4
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/grid/small_bit_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type GridBits = u64;

/// A grid with up to 64 tiles holding a single bit of information.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SmallBitGrid<T> {
width: u8,
height: u8,
Expand Down
1 change: 1 addition & 0 deletions src/grid/vec_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::grid::{FiniteGrid, Grid};

/// Grid with arbitrary finite size
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct VecGrid<T> {
width: u8,
height: u8,
Expand Down
1 change: 1 addition & 0 deletions src/loopy/impartial/games/wind_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{collections::HashSet, fmt::Display};

/// Modular subtraction game
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WindUp {
graph: Vec<Vertex>,
subtraction_set: Vec<u32>,
Expand Down
2 changes: 2 additions & 0 deletions src/loopy/impartial/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fmt::Display;

/// Vertex set used during graph orbiting
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum UnresolvedVertex {
/// Vertex that is equal to some finite nimber or a loop.
Resolved(Vertex),
Expand All @@ -15,6 +16,7 @@ pub enum UnresolvedVertex {

/// Value of graph vertex - finite or infinite
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Vertex {
/// Vertex that is equal to some finite nimber.
Value(Nimber),
Expand Down
1 change: 1 addition & 0 deletions src/numeric/nimber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::fmt::Display;
/// Addition is overloaded to Nim sum.
#[repr(transparent)]
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Nimber(u32);

impl Nimber {
Expand Down
1 change: 1 addition & 0 deletions src/short/impartial/games/pseudo_quicksort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::fmt::Display;

/// See [`pseudo_quickcheck`](self) header
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PseudoQuicksort {
sequence: Vec<u32>,
}
Expand Down
1 change: 1 addition & 0 deletions src/short/impartial/games/quicksort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{display, short::impartial::impartial_game::ImpartialGame};

/// See [quickcheck](self) header
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Quicksort {
sequence: Vec<u32>,
}
Expand Down
2 changes: 2 additions & 0 deletions src/short/impartial/games/subtraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{display, numeric::nimber::Nimber};

/// Subtraction game played on an arbitrary finite subtraction set
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Sub {
// Invariant: sorted
subtraction_set: Vec<u32>,
Expand Down Expand Up @@ -48,6 +49,7 @@ impl Sub {

/// Grundy Sequence of [Sub] iterator using Grundy scale method.
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct GrundySequence {
/// The underlying subtraction game ruleset
game: Sub,
Expand Down
6 changes: 5 additions & 1 deletion src/short/partizan/canonical_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::{

/// A number-up-star game position that is a sum of a number, up and, nimber.
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Nus {
number: DyadicRationalNumber,
up_multiple: i32,
Expand Down Expand Up @@ -320,6 +321,7 @@ impl Display for Nus {

/// Left and Right moves from a given position
#[derive(Debug, Hash, Clone, PartialEq, Eq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Moves {
/// Left player's moves
pub left: Vec<CanonicalForm>,
Expand Down Expand Up @@ -796,6 +798,7 @@ impl_from_str_via_nom!(Moves);
/// Note that ordering is defined structurally for the sake of data structures. For proper partial
/// ordering see instance for [`CanonicalForm`].
#[derive(Debug, Hash, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
enum CanonicalFormInner {
/// Number Up Star sum
Nus(Nus),
Expand All @@ -804,9 +807,10 @@ enum CanonicalFormInner {
Moves(Moves),
}

/// Canonical game form
#[repr(transparent)]
#[derive(Debug, Hash, Clone, PartialEq, Eq)]
/// Canonical game form
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CanonicalForm {
inner: CanonicalFormInner,
}
Expand Down
2 changes: 2 additions & 0 deletions src/short/partizan/games/domineering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{fmt::Display, str::FromStr};

/// Tile on a Domineering grid
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Tile)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Tile {
/// Tile where domino can be placed
#[tile(char('.'), bool(false), default)]
Expand All @@ -26,6 +27,7 @@ pub enum Tile {

/// A Domineering position on a rectengular grid.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Domineering<G = SmallBitGrid<Tile>> {
grid: G,
}
Expand Down
2 changes: 2 additions & 0 deletions src/short/partizan/games/fission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{

/// Tile in the game of Fission
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Tile)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Tile {
/// Empty tile without stones
#[tile(char('.'), default)]
Expand All @@ -30,6 +31,7 @@ pub enum Tile {

/// Game of Fission
#[derive(Debug, Hash, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Fission<G = VecGrid<Tile>> {
grid: G,
}
Expand Down
3 changes: 3 additions & 0 deletions src/short/partizan/games/ski_jumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::{fmt::Display, hash::Hash, str::FromStr};

/// Skier type
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Skier {
/// Skier that can jump over skiers below
Jumper,
Expand All @@ -28,6 +29,7 @@ pub enum Skier {

/// Ski Jumps game grid tile
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Tile {
/// Empty tile, without skiers
Empty,
Expand Down Expand Up @@ -71,6 +73,7 @@ impl CharTile for Tile {
// NOTE: Consider caching positions of left and right skiers to avoid quadratic loops
/// Ski Jumps game
#[derive(Debug, Hash, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SkiJumps<G = VecGrid<Tile>> {
grid: G,
}
Expand Down
2 changes: 2 additions & 0 deletions src/short/partizan/games/toads_and_frogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{

/// Tile on the Toads and Frogs board
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Tile)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Tile {
/// Empty tile without any creature
#[tile(default, char('.'))]
Expand All @@ -34,6 +35,7 @@ pub enum Tile {

/// Singular row of the Toads and Frogs board
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ToadsAndFrogs {
tiles: Vec<Tile>,
}
Expand Down
1 change: 1 addition & 0 deletions src/short/partizan/thermograph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{cmp::Ordering, fmt::Display, iter::once};

/// See [thermograph](self) header
#[derive(Debug, Hash, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Thermograph {
pub(crate) left_wall: Trajectory,
pub(crate) right_wall: Trajectory,
Expand Down
1 change: 1 addition & 0 deletions src/short/partizan/trajectory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{cmp::Ordering, fmt::Display};
/// A continuous piecewise linear trajectory with rational slopes and critical points.
/// Each trajectory is defined for all rational numbers on the interval `-1 ≤ x < ∞`.
#[derive(Debug, Hash, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Trajectory {
/// A `critical point` is a point at which the trajectory changes slope, and must be strictly
/// between `-1` and `∞`.
Expand Down

0 comments on commit 6fdb7c4

Please sign in to comment.