Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try use GPU (Tho seems to be very limited) #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 69 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "MIT"
edition = "2021"

[dependencies]
cards = {path = "./cards", features = ["std"]}
colored = "2.0"
petgraph = "0.6.5"
dialoguer = "0.11.0"
Expand Down
8 changes: 8 additions & 0 deletions cards/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/target
.DS_Store
.vscode/*
/data
.todo
.env
.swp
profile.json
156 changes: 156 additions & 0 deletions cards/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions cards/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "cards"
version = "0.1.0"
edition = "2021"

[dependencies]
rand = { version = "0.8.5", default-features = false }
itertools = { version = "0.13.0", default-features = false }

[target.'cfg(target_arch = "spirv")'.dependencies]
spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu.git" }

[features]
default = ["no_std"]
std = ["rand/std", "rand/std_rng", "rand/small_rng", "itertools/use_std"]
no_std = []

[lib]
name = "cards"
path = "src/lib.rs"
1 change: 1 addition & 0 deletions src/cards/board.rs → cards/src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl From<Board> for Hand {
board.0
}
}
#[cfg(feature = "std")]
impl std::fmt::Display for Board {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
Expand Down
3 changes: 3 additions & 0 deletions src/cards/card.rs → cards/src/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl Card {
pub fn suit(&self) -> Suit {
Suit::from(self.0 % 4)
}
#[cfg(feature = "std")]
pub fn draw() -> Card {
use rand::Rng;
let ref mut rng = rand::thread_rng();
Expand Down Expand Up @@ -78,13 +79,15 @@ impl From<Card> for u64 {
}
}

#[cfg(feature = "std")]
impl std::fmt::Display for Card {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}{}", self.rank(), self.suit())
}
}

/// str isomorphism
#[cfg(feature = "std")]
impl From<&str> for Card {
fn from(s: &str) -> Self {
assert!(s.len() == 2);
Expand Down
3 changes: 3 additions & 0 deletions src/cards/deck.rs → cards/src/deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl Deck {
/// remove a random card from the deck.
/// different from Hand::draw() since that removes
/// highest card deterministically
#[cfg(feature = "std")]
pub fn draw(&mut self) -> Card {
assert!(self.0.size() > 0);
let n = self.0.size();
Expand All @@ -33,13 +34,15 @@ impl Deck {

/// remove two cards from the deck
/// to deal as a Hole
#[cfg(feature = "std")]
pub fn hole(&mut self) -> Hole {
let a = self.draw();
let b = self.draw();
Hole::from((a, b))
}
}

#[cfg(feature = "std")]
impl Iterator for Deck {
type Item = Card;
fn next(&mut self) -> Option<Self::Item> {
Expand Down
Loading