Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d5b982bba | |||
| 987d8bd0f4 | |||
| 99b49e629e | |||
| 2eaa99e82d | |||
| 0cdfa5446a |
Generated
+3
@@ -25,6 +25,7 @@ name = "card_game"
|
|||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -130,6 +131,7 @@ version = "0.3.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"card_game",
|
"card_game",
|
||||||
"rand",
|
"rand",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -238,6 +240,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -8,8 +8,12 @@ description = "Card game library."
|
|||||||
authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||||
keywords = ["card", "cards", "solitaire", "klondike"]
|
keywords = ["card", "cards", "solitaire", "klondike"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
serde = ["dep:serde"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
arrayvec = { version = "0.7.6", registry = "Quaternions", features = ["len_u8"], default-features = false }
|
arrayvec = { version = "0.7.6", registry = "Quaternions", features = ["len_u8"], default-features = false }
|
||||||
|
serde = { version = "1", optional = true, default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ pub trait Game: Clone {
|
|||||||
|
|
||||||
/// card_game supports up to 4 identifiably separate decks.
|
/// card_game supports up to 4 identifiably separate decks.
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum Deck {
|
pub enum Deck {
|
||||||
Deck1 = 0b00,
|
Deck1 = 0b00,
|
||||||
Deck2 = 0b01,
|
Deck2 = 0b01,
|
||||||
@@ -48,6 +49,7 @@ impl Deck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum Suit {
|
pub enum Suit {
|
||||||
Spades = 0b00,
|
Spades = 0b00,
|
||||||
Hearts = 0b01,
|
Hearts = 0b01,
|
||||||
@@ -77,6 +79,7 @@ impl Suit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum Rank {
|
pub enum Rank {
|
||||||
Ace = 1,
|
Ace = 1,
|
||||||
Two = 2,
|
Two = 2,
|
||||||
@@ -146,6 +149,8 @@ impl Rank {
|
|||||||
/// 2 bits for suit ID
|
/// 2 bits for suit ID
|
||||||
/// 4 bits for card Value
|
/// 4 bits for card Value
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||||
pub struct Card(core::num::NonZeroU8);
|
pub struct Card(core::num::NonZeroU8);
|
||||||
impl Card {
|
impl Card {
|
||||||
pub const fn new(deck: Deck, suit: Suit, rank: Rank) -> Self {
|
pub const fn new(deck: Deck, suit: Suit, rank: Rank) -> Self {
|
||||||
|
|||||||
@@ -3,9 +3,13 @@ name = "klondike"
|
|||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
serde = ["dep:serde"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
card_game.workspace = true
|
card_game.workspace = true
|
||||||
rand = { version = "0.10.1", default-features = false, features = ["std_rng"] }
|
rand = { version = "0.10.1", default-features = false, features = ["std_rng"] }
|
||||||
|
serde = { version = "1", optional = true, default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ impl KlondikeStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum Tableau {
|
pub enum Tableau {
|
||||||
Tableau1,
|
Tableau1,
|
||||||
Tableau2,
|
Tableau2,
|
||||||
@@ -147,6 +148,7 @@ impl Tableau {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum Foundation {
|
pub enum Foundation {
|
||||||
Foundation1,
|
Foundation1,
|
||||||
Foundation2,
|
Foundation2,
|
||||||
@@ -167,6 +169,7 @@ impl Foundation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum KlondikePile {
|
pub enum KlondikePile {
|
||||||
Tableau(Tableau),
|
Tableau(Tableau),
|
||||||
Stock,
|
Stock,
|
||||||
@@ -200,6 +203,7 @@ impl From<Foundation> for KlondikePile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum SkipCards {
|
pub enum SkipCards {
|
||||||
Skip0,
|
Skip0,
|
||||||
Skip1,
|
Skip1,
|
||||||
@@ -238,6 +242,7 @@ impl SkipCards {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct TableauStack {
|
pub struct TableauStack {
|
||||||
pub tableau: Tableau,
|
pub tableau: Tableau,
|
||||||
pub skip_cards: SkipCards,
|
pub skip_cards: SkipCards,
|
||||||
@@ -271,6 +276,7 @@ impl TableauStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum KlondikePileStack {
|
pub enum KlondikePileStack {
|
||||||
Tableau(TableauStack),
|
Tableau(TableauStack),
|
||||||
Stock,
|
Stock,
|
||||||
@@ -294,6 +300,7 @@ impl KlondikePileStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct DstFoundation {
|
pub struct DstFoundation {
|
||||||
pub src: KlondikePile,
|
pub src: KlondikePile,
|
||||||
pub foundation: Foundation,
|
pub foundation: Foundation,
|
||||||
@@ -317,6 +324,7 @@ impl DstFoundation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct DstTableau {
|
pub struct DstTableau {
|
||||||
pub src: KlondikePileStack,
|
pub src: KlondikePileStack,
|
||||||
pub tableau: Tableau,
|
pub tableau: Tableau,
|
||||||
@@ -340,6 +348,7 @@ impl DstTableau {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum KlondikeInstruction {
|
pub enum KlondikeInstruction {
|
||||||
DstFoundation(DstFoundation),
|
DstFoundation(DstFoundation),
|
||||||
DstTableau(DstTableau),
|
DstTableau(DstTableau),
|
||||||
|
|||||||
Reference in New Issue
Block a user